Class: Proz::Freelancer

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key:, uuid:) ⇒ Freelancer

Returns a new instance of Freelancer.



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

def initialize(key:, uuid:)
  @key = key
  @uuid = uuid
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



32
33
34
# File 'lib/proz/freelancer.rb', line 32

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

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



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

def key
  @key
end

#uuidObject (readonly)

Returns the value of attribute uuid.



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

def uuid
  @uuid
end

Instance Method Details

#freelancerObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/proz/freelancer.rb', line 13

def freelancer
  case
  when freelancer_response.has_key?('error')
    if freelancer_response['error'].eql?('invalid_api_key')
      raise 'Invalid API Key'
    else
      raise 'Invalid Request'
    end
  when freelancer_response.has_key?('error_messages')
    if freelancer_response['error_messages'][0].eql?('No freelancer was found with that UUID.')
      raise 'No freelancer was found with that UUID'
    else
      raise 'Invalid Request'
    end
  else
    freelancer_response['data']
  end
end