class Thumbtack::Client
Wraps each interaction with the Pinboard API
Attributes
Token used by the client to make authenticated requests
@example
client.adapter # => #<Thumbtack::Adapters::BasicAdapter...
@return [Adapter]
@api public
Token used by the client to make authenticated requests
@example
client.token # => 'C9044F4047891CEA74FE'
@return [String]
@api public
Username used by the client to make authenticated requests
@example
client.username # => 'maciej'
@return [String]
@api public
Public Class Methods
Initialize a Client
@example
client = Client.new(username, token)
@param [String] username
the user to authenticate with
@param [String] token
the API token for the user account, found on the Pinboard settings page
@param [Hash] options
options for the construction of the client
@option options [BasicAdapter] :adapter
an adapter to use for communicating with the Pinboard API
@api public
# File lib/thumbtack/client.rb, line 51 def initialize(username, token, options = EMPTY_HASH) @username = username @token = token @adapter = options.fetch(:adapter) do Adapters::BasicAdapter.new(@username, @token) end end
Public Instance Methods
Perform an action request against the Pinboard API
@param [String] path
the path to fetch from, relative to from the base Pinboard API URL
@param [Hash] params
query parameters to append to the URL
@return [Hash] the response parsed from the JSON
@raise [RateLimitError] if the response is rate-limited @raise [ResultError] if the result code isn't “done”
@api private @see pinboard.in/api/#errors
# File lib/thumbtack/client.rb, line 91 def action(path, params) response = @adapter.get(path, params) unless response['result_code'] == 'done' raise ResultError, response['result_code'] end self end
Retrieve JSON from the Pinboard API
@param [String] path
the path to fetch from, relative to from the base Pinboard API URL
@param [Hash] params
query parameters to append to the URL
@return [Hash] the response parsed from the JSON
@raise [RateLimitError] if the response is rate-limited
@api private
# File lib/thumbtack/client.rb, line 72 def get(path, params = EMPTY_HASH) @adapter.get(path, params) end
Access notes-related API calls
@example
notes = client.notes
@return [Notes]
@api public
# File lib/thumbtack/client.rb, line 144 def notes Notes.new(self) end
Access posts-related API calls
@example
posts = client.posts
@return [Posts]
@api public
# File lib/thumbtack/client.rb, line 108 def posts Posts.new(self) end
Access user-related API calls
@example
user = client.user
@return [User]
@api public
# File lib/thumbtack/client.rb, line 132 def user User.new(self) end