Class: GetAccept::Api

Inherits:
Object
  • Object
show all
Defined in:
lib/get_accept/api.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Api

Returns a new instance of Api.



18
19
20
21
# File 'lib/get_accept/api.rb', line 18

def initialize(options = {})
  @token = options[:token]
  @client = HTTP.auth("Bearer #{@token}").headers('Content-Type' => 'application/json')
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



35
36
37
38
39
40
# File 'lib/get_accept/api.rb', line 35

def method_missing(method, *args)
  klass = method.to_s.split('_').collect(&:capitalize).join
  Object.const_get("GetAccept::#{klass}").new(@client)
rescue NameError
  super
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



5
6
7
# File 'lib/get_accept/api.rb', line 5

def client
  @client
end

Class Method Details

.get_token(options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/get_accept/api.rb', line 7

def self.get_token(options = {})
  payload = {
              email: options[:email],
              password: options[:password],
              client: options[:client],
              entity_id: options[:entity_id],
            }
  HTTP.post("#{API_BASE}/auth", json: payload)
end

Instance Method Details

#open_url(url) ⇒ Object



31
32
33
# File 'lib/get_accept/api.rb', line 31

def open_url url
  url = URI.encode("https://app.getaccept.com/auth/sso/login?token=#{@token}&go=#{url}")
end

#refresh_tokenObject



23
24
25
# File 'lib/get_accept/api.rb', line 23

def refresh_token
  client.get("#{API_BASE}/refresh",)
end

#respond_to_missing?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
45
46
47
48
# File 'lib/get_accept/api.rb', line 42

def respond_to_missing?(method, include_private = false)
  klass = method.to_s.capitalize
  Object.const_get("GetAccept::#{klass}")
  true
rescue NameError
  super
end

#revoke_tokenObject



27
28
29
# File 'lib/get_accept/api.rb', line 27

def revoke_token
  client.get("#{API_BASE}/revoke")
end