Class: Thron::Gateway::Contact

Inherits:
Session show all
Defined in:
lib/thron/gateway/contact.rb

Constant Summary collapse

PACKAGE =
Package.new(:xcontact, :resources, self.service_name)

Constants inherited from Base

Base::NO_ACTIVE_SESSION

Instance Attribute Summary

Attributes inherited from Base

#token_id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Session

#initialize

Methods included from Pageable

included

Methods inherited from Base

#check_session, client_id, #client_id, service_name

Methods included from Routable

included, info, #route

Constructor Details

This class inherits a constructor from Thron::Gateway::Session

Class Method Details

.routesObject



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/thron/gateway/contact.rb', line 13

def self.routes
  @routes ||= {
    add_contact_key: Route::factory(name: 'addKey', package: PACKAGE, params: [client_id]),
    contact_detail: Route::factory(name: 'detail', package: PACKAGE, verb: Route::Verbs::GET, params: [client_id]),
    insert_contact: Route::factory(name: 'insert', package: PACKAGE, params: [client_id]),
    list_contacts: Route::factory(name: 'list', package: PACKAGE, params: [client_id]),
    list_contact_keys: Route::factory(name: 'listKey', package: PACKAGE, params: [client_id]),
    remove_contact_key: Route::factory(name: 'removeKey', package: PACKAGE, params: [client_id]),
    update_contact: Route::factory(name: 'update', package: PACKAGE, params: [client_id])
  }
end

Instance Method Details

#add_contact_key(options = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/thron/gateway/contact.rb', line 25

def add_contact_key(options = {})
  contact_id = options[:contact_id]
  ik = options[:ik]
  body = { 
    contactId: contact_id,
    ik: ik
  }
  route(to: __callee__, body: body, token_id: token_id) do |response|
    response.body = Entity::Base::factory(response.body.fetch('item') { {} })
  end
end

#contact_detail(options = {}) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/thron/gateway/contact.rb', line 37

def contact_detail(options = {})
  contact_id = options[:contact_id]
  query = { 
    contactId: contact_id,
  }
  route(to: __callee__, query: query, token_id: token_id) do |response|
    response.body = Entity::Base::factory(response.body.fetch('item') { {} })
  end
end

#insert_contact(options = {}) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/thron/gateway/contact.rb', line 47

def insert_contact(options = {})
  name = options[:name]
  ik = options[:ik]
  body = { 
    value: {
      ik: ik,
      name: name
    }
  }
  route(to: __callee__, body: body, token_id: token_id) do |response|
    response.body = Entity::Base::factory(response.body.fetch('item') { {} })
  end
end

#list_contact_keys(options = {}) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/thron/gateway/contact.rb', line 77

def list_contact_keys(options = {})
  search_key = options[:search_key]
  offset = options[:offset].to_i
  limit = options[:limit].to_i
  body = { 
    criteria: {
      searchKey: search_key
    },
    offset: offset,
    limit: limit
  }
  route(to: __callee__, body: body, token_id: token_id) do |response|
    response.body = response.body.fetch('items') { [] }
  end
end

#list_contacts(options = {}) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/thron/gateway/contact.rb', line 61

def list_contacts(options = {})
  criteria = options.fetch(:criteria) { {} }
  option = options.fetch(:option) { {} }
  offset = options[:offset].to_i
  limit = options[:limit].to_i
  body = { 
    criteria: criteria,
    option: option,
    offset: offset,
    limit: limit
  }
  route(to: __callee__, body: body, token_id: token_id) do |response|
    response.body = Entity::Base::factory(response.body.fetch('items') { [] })
  end
end

#remove_contact_key(options = {}) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
# File 'lib/thron/gateway/contact.rb', line 93

def remove_contact_key(options = {})
  contact_id = options[:contact_id]
  key = options[:key]
  body = { 
    contactId: contact_id,
    key: key
  }
  route(to: __callee__, body: body, token_id: token_id) do |response|
    response.body = Entity::Base::factory(response.body.fetch('item') { {} })
  end
end

#update_contact(options = {}) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/thron/gateway/contact.rb', line 105

def update_contact(options = {})
  contact_id = options[:contact_id]
  name = options[:name]
  body = { 
    contactId: contact_id,
    update: {
      name: name
    }
  }
  route(to: __callee__, body: body, token_id: token_id) do |response|
    response.body = Entity::Base::factory(response.body.fetch('item') { {} })
  end
end