Class: Pingboard::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/pingboard/client.rb

Constant Summary collapse

URL_HOSTNAME =
'https://app.pingboard.com'.freeze
URL_API_VERSION_PATH =
'/api/v2'.freeze
URL_SEARCH_USERS_PATH =
'/search/users'.freeze
URL_USERS_PATH =
'/users'.freeze
URL_STATUSES_PATH =
'/statuses'.freeze
URL_STATUS_TYPES_PATH =
'/status_types'.freeze
URL_OAUTH_TOKEN_PATH =
'/oauth/token'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request = Pingboard::Request, options = {}) {|_self| ... } ⇒ Client

Returns a new instance of Client.

Yields:

  • (_self)

Yield Parameters:



15
16
17
18
19
20
21
22
# 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

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



12
13
14
# File 'lib/pingboard/client.rb', line 12

def access_token
  @access_token
end

#connectionObject

Returns the value of attribute connection.



12
13
14
# File 'lib/pingboard/client.rb', line 12

def connection
  @connection
end

#service_app_idObject

Returns the value of attribute service_app_id.



12
13
14
# File 'lib/pingboard/client.rb', line 12

def service_app_id
  @service_app_id
end

#service_app_secretObject

Returns the value of attribute service_app_secret.



12
13
14
# File 'lib/pingboard/client.rb', line 12

def service_app_secret
  @service_app_secret
end

#token_expiration_timeObject

Returns the value of attribute token_expiration_time.



12
13
14
# File 'lib/pingboard/client.rb', line 12

def token_expiration_time
  @token_expiration_time
end

#token_expires_inObject

Returns the value of attribute token_expires_in.



12
13
14
# File 'lib/pingboard/client.rb', line 12

def token_expires_in
  @token_expires_in
end

Instance Method Details

#search(query, options = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
# 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 = {}) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
# 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_typesObject



73
74
75
76
77
78
79
80
81
82
83
# 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 = {}) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
# 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 = {}) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# 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