Class: Gamewisp::Client
- Inherits:
-
Object
- Object
- Gamewisp::Client
- Defined in:
- lib/gamewisp/client.rb
Instance Attribute Summary collapse
-
#auth ⇒ Object
Returns the value of attribute auth.
-
#token_store ⇒ Object
Returns the value of attribute token_store.
Instance Method Summary collapse
- #authorize ⇒ Object
- #get_subscribers ⇒ Object
-
#initialize ⇒ Client
constructor
Only works if this class is derived (includes) HTTParty.
- #renew_access_token ⇒ Object
Constructor Details
#initialize ⇒ Client
26 27 28 29 |
# File 'lib/gamewisp/client.rb', line 26 def initialize self.token_store = TokenStore.new self.auth = Authorizer.new 'createauth', self.token_store end |
Instance Attribute Details
#auth ⇒ Object
Returns the value of attribute auth.
17 18 19 |
# File 'lib/gamewisp/client.rb', line 17 def auth @auth end |
#token_store ⇒ Object
Returns the value of attribute token_store.
16 17 18 |
# File 'lib/gamewisp/client.rb', line 16 def token_store @token_store end |
Instance Method Details
#authorize ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/gamewisp/client.rb', line 31 def puts "Visit the following URL in your browser and authorize #{token_store.app_name} to access your subscription metrics" puts " #{auth.}" puts server = auth.create_server_instance auth_result = server.get_authentication_token puts auth_result if auth_result["code"] puts "Authorization received" else raise GamewispError, "Authorization failed." end auth.renew_tokens_with_auth_code auth_result["code"] end |
#get_subscribers ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/gamewisp/client.rb', line 57 def get_subscribers url = "https://api.gamewisp.com/pub/v1/channel/subscribers" dbg "Client.get_subscribers [access_token]", token_store.access_token response = HTTParty .get(url, :query => { :access_token => token_store.access_token, :include => 'user,channel,benefits', } ) dbg "Client.get_subscribers [response.code]", response.code dbg "Client.get_subscribers [response]", response response end |
#renew_access_token ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/gamewisp/client.rb', line 49 def renew_access_token if token_store.refresh_token.nil? || token_store.refresh_token.empty? return end auth.renew_tokens_with_refresh_token token_store.refresh_token end |