class Pingboard::Client
Constants
- URL_API_VERSION_PATH
- URL_HOSTNAME
- URL_OAUTH_TOKEN_PATH
- URL_SEARCH_USERS_PATH
- URL_STATUSES_PATH
- URL_STATUS_TYPES_PATH
- URL_USERS_PATH
Attributes
access_token[RW]
connection[RW]
service_app_id[RW]
service_app_secret[RW]
token_expiration_time[RW]
token_expires_in[RW]
Public Class Methods
new(request=Pingboard::Request, options={}) { |self| ... }
click to toggle source
# File lib/pingboard/client.rb, line 15 def initialize(request=Pingboard::Request, options={}) options.each do |key, value| instance_variable_set("@#{key}", value) end yield(self) if block_given? @token_expiration_time = Time.now @request = request end
Public Instance Methods
search(query, options={})
click to toggle source
# File lib/pingboard/client.rb, line 24 def search(query, options={}) options.merge!(q: query) response = build_request( self, :get, URL_API_VERSION_PATH + URL_SEARCH_USERS_PATH, {'Authorization' => "Bearer #{access_token}" }, nil, options ).do JSON.parse(response.body) end
status(status_id, options={})
click to toggle source
# File lib/pingboard/client.rb, line 61 def status(status_id, options={}) response = build_request( self, :get, URL_API_VERSION_PATH + URL_STATUSES_PATH + "/#{status_id}", {'Authorization' => "Bearer #{access_token}" }, nil, options ).do JSON.parse(response.body) end
status_types()
click to toggle source
# File lib/pingboard/client.rb, line 73 def status_types response = build_request( self, :get, URL_API_VERSION_PATH + URL_STATUS_TYPES_PATH, {'Authorization' => "Bearer #{access_token}" }, nil, nil ).do JSON.parse(response.body) end
user(user_id, options={})
click to toggle source
# File lib/pingboard/client.rb, line 49 def user(user_id, options={}) response = build_request( self, :get, URL_API_VERSION_PATH + URL_USERS_PATH + "/#{user_id}", {'Authorization' => "Bearer #{access_token}" }, nil, options ).do JSON.parse(response.body) end
users(options={})
click to toggle source
# File lib/pingboard/client.rb, line 37 def users(options={}) response = build_request( self, :get, URL_API_VERSION_PATH + URL_USERS_PATH, {'Authorization' => "Bearer #{access_token}" }, nil, options ).do JSON.parse(response.body) end
Private Instance Methods
access_token_expired?()
click to toggle source
# File lib/pingboard/client.rb, line 107 def access_token_expired? Time.now > token_expiration_time end
access_token_request()
click to toggle source
# File lib/pingboard/client.rb, line 118 def access_token_request @access_token_request = build_request( self, :post, URL_OAUTH_TOKEN_PATH, { 'Content-Type' => 'application/x-www-form-urlencoded' }, { 'client_id' => "#{service_app_id}", 'client_secret' => "#{service_app_secret}" }, { 'grant_type' => 'client_credentials' } ).do end
build_request(client, http_verb, path, headers, body, params)
click to toggle source
# File lib/pingboard/client.rb, line 96 def build_request(client, http_verb, path, headers, body, params) @request.new( client: client, http_verb: http_verb, path: path, headers: headers, body: body, params: params ) end
new_access_token()
click to toggle source
# File lib/pingboard/client.rb, line 111 def new_access_token response_body = JSON.parse(access_token_request.body) @token_expires_in = response_body['expires_in'] @token_expiration_time = Time.now + @token_expires_in.to_i response_body['access_token'] end