Class: Centaman::Service::Member

Inherits:
Centaman::Service show all
Includes:
JsonWrapper
Defined in:
lib/centaman/service/member.rb

Constant Summary

Constants inherited from Wrapper

Wrapper::DEFAULT_TIMEOUT_TIME

Instance Attribute Summary collapse

Attributes inherited from Wrapper

#api_password, #api_token, #api_url, #api_username, #proxie_host, #proxie_password, #proxie_port, #proxie_user

Class Method Summary collapse

Instance Method Summary collapse

Methods included from JsonWrapper

#additional_hash_to_serialize_after_response, #build_objects, #final_object_class, #objects

Methods inherited from Centaman::Service

#after_post, #fetch_all, #post, #put

Methods inherited from Wrapper

#generate_token, #headers, #initialize, #options, #options_hash, #payload, #payload_key, #proxy_hash, #wrap_request_in_case_of_timeout

Constructor Details

This class inherits a constructor from Centaman::Wrapper

Instance Attribute Details

#emailObject (readonly)

Returns the value of attribute email.



5
6
7
# File 'lib/centaman/service/member.rb', line 5

def email
  @email
end

#member_codeObject (readonly)

Returns the value of attribute member_code.



5
6
7
# File 'lib/centaman/service/member.rb', line 5

def member_code
  @member_code
end

Class Method Details

.find(id) ⇒ Object

given primary member id, returns array with primary and associated secondary member records



29
30
31
32
33
34
# File 'lib/centaman/service/member.rb', line 29

def self.find(id)
  members = self.find_members_by_id(id)
  return unless members && members.any?
  return members if members.detect { |obj| obj.is_primary }
  find_members_by_id(members[0].primary_member_id)
end

.find_member(id) ⇒ Object

returns individual member object matching the given id



37
38
39
40
# File 'lib/centaman/service/member.rb', line 37

def self.find_member(id)
  member_array = find(id) || []
  member_array.detect { |obj| obj.id == id }
end

Instance Method Details

#after_init(args) ⇒ Object



7
8
9
10
11
# File 'lib/centaman/service/member.rb', line 7

def after_init(args)
  @member_code = args.fetch(:member_code, nil).try(:to_i)
  @email = args.fetch(:email, nil)
  required_args
end

#build_object(resp) ⇒ Object



21
22
23
24
25
26
# File 'lib/centaman/service/member.rb', line 21

def build_object(resp)
  return build_objects(resp) if resp.respond_to?(:map)

  return not_found(resp) unless resp.respond_to?(:merge)
  @build_object ||= object_class.new(resp.merge(additional_hash_to_serialize_after_response))
end

#endpointObject



13
14
15
# File 'lib/centaman/service/member.rb', line 13

def endpoint
  member_code ? member_endpoint(:member_code) : member_endpoint(:email)
end

#object_classObject



17
18
19
# File 'lib/centaman/service/member.rb', line 17

def object_class
  Centaman::Object::Member
end