Class: Proz::Profile

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/proz/profile.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token:) ⇒ Profile

Returns a new instance of Profile.



8
9
10
# File 'lib/proz/profile.rb', line 8

def initialize(token:)
  @token = token
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



27
28
29
# File 'lib/proz/profile.rb', line 27

def method_missing(name, *args, &block)
  profile.has_key?(name.to_s) ? profile[name.to_s] : super
end

Instance Attribute Details

#tokenObject (readonly)

Returns the value of attribute token.



7
8
9
# File 'lib/proz/profile.rb', line 7

def token
  @token
end

Instance Method Details

#profileObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/proz/profile.rb', line 12

def profile
  case
  when profile_response.has_key?('error')
    if profile_response['error'].eql?('invalid_token')
      raise 'Invalid Token'
    elsif profile_response['error'].eql?('expired_token')
      raise 'Access Token Expired'
    else
      raise 'Invalid Request'
    end
  else
    profile_response['data']
  end
end