class Thumbtack::Client

Wraps each interaction with the Pinboard API

Attributes

adapter[R]

Token used by the client to make authenticated requests

@example

client.adapter  # => #<Thumbtack::Adapters::BasicAdapter...

@return [Adapter]

@api public

token[R]

Token used by the client to make authenticated requests

@example

client.token  # => 'C9044F4047891CEA74FE'

@return [String]

@api public

username[R]

Username used by the client to make authenticated requests

@example

client.username  # => 'maciej'

@return [String]

@api public

Public Class Methods

new(username, token, options = EMPTY_HASH) click to toggle source

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

action(path, params) click to toggle source

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
get(path, params = EMPTY_HASH) click to toggle source

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
notes() click to toggle source

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
posts() click to toggle source

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
tags() click to toggle source

Access tags-related API calls

@example

tags = client.tags

@return [Tags]

@api public

# File lib/thumbtack/client.rb, line 120
def tags
  Tags.new(self)
end
user() click to toggle source

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