Class: ComagicClient

Inherits:
Object
  • Object
show all
Defined in:
lib/comagic_client.rb

Overview

This class creates a new comagic connector instanse

Defined Under Namespace

Classes: ApiError

Instance Method Summary collapse

Constructor Details

#initialize(login, password) ⇒ ComagicClient

Set up a new connector instanse



17
18
19
20
21
# File 'lib/comagic_client.rb', line 17

def initialize(, password)
  @session_key = nil
  @api_url = 'http://api.comagic.ru/api'
  @login, @password = , password
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *arguments, &block) ⇒ Object

Pass post, get, delete, put and patch to the request method



155
156
157
158
159
160
161
# File 'lib/comagic_client.rb', line 155

def method_missing(method_name, *arguments, &block)
  if method_name.to_s =~ /(post|get|put|patch|delete)/
    request($1.to_sym, *arguments, &block)
  else
    super
  end
end

Instance Method Details

#ac(options = {}) ⇒ Object

Get ad campaigns



44
45
46
47
48
# File 'lib/comagic_client.rb', line 44

def ac(options = {})
  require_auth!
  options.merge!({ session_key: @session_key }).not_nils!
  get 'v1/ac', options
end

#call(options = {}) ⇒ Object

Get call



79
80
81
82
83
# File 'lib/comagic_client.rb', line 79

def call(options = {})
  require_auth!
  options.merge!({ session_key: @session_key }).not_nils!
  get 'v1/call', options
end

#chat(options = {}) ⇒ Object

Get chat



86
87
88
89
90
# File 'lib/comagic_client.rb', line 86

def chat(options = {})
  require_auth!
  options.merge!({ session_key: @session_key }).not_nils!
  get 'v1/chat', options
end

#chat_message(options = {}) ⇒ Object

Get chat_message



93
94
95
96
97
# File 'lib/comagic_client.rb', line 93

def chat_message(options = {})
  require_auth!
  options.merge!({ session_key: @session_key }).not_nils!
  get 'v1/chat_message', options
end

#communication(options = {}) ⇒ Object

Get communications



58
59
60
61
62
# File 'lib/comagic_client.rb', line 58

def communication(options = {})
  require_auth!
  options.merge!({ session_key: @session_key }).not_nils!
  get 'v1/communication', options
end

#create_site(options = {}) ⇒ Object



148
149
150
151
152
# File 'lib/comagic_client.rb', line 148

def create_site(options = {})
  require_auth!
  options.merge!({ session_key: @session_key }).not_nils!
  post 'v1/create_site', options
end

#customer_list(options = {}) ⇒ Object

Get customer_list



142
143
144
145
146
# File 'lib/comagic_client.rb', line 142

def customer_list(options = {})
  require_auth!
  options.merge!({ session_key: @session_key }).not_nils!
  get 'v1/customer_list', options
end

#get_cdr_in(options = {}) ⇒ Object

Get get_cdr_in



128
129
130
131
132
# File 'lib/comagic_client.rb', line 128

def get_cdr_in(options = {})
  require_auth!
  options.merge!({ session_key: @session_key }).not_nils!
  get 'v1/get_cdr_in', options
end

#get_cdr_out(options = {}) ⇒ Object

Get get_cdr_out



135
136
137
138
139
# File 'lib/comagic_client.rb', line 135

def get_cdr_out(options = {})
  require_auth!
  options.merge!({ session_key: @session_key }).not_nils!
  get 'v1/get_cdr_out', options
end

#goal(options = {}) ⇒ Object

Get goal



72
73
74
75
76
# File 'lib/comagic_client.rb', line 72

def goal(options = {})
  require_auth!
  options.merge!({ session_key: @session_key }).not_nils!
  get 'v1/goal', options
end

#loginObject

Perform login with login and password specified in the initialize method



24
25
26
27
# File 'lib/comagic_client.rb', line 24

def 
  response = post "login", login: @login, password: @password
  @session_key = response['session_key']
end

#logoutObject

Perform logout



31
32
33
34
# File 'lib/comagic_client.rb', line 31

def logout
  require_auth!
  get "logout", session_key: @session_key
end

#offline_message(options = {}) ⇒ Object

Get offline_message



100
101
102
103
104
# File 'lib/comagic_client.rb', line 100

def offline_message(options = {})
  require_auth!
  options.merge!({ session_key: @session_key }).not_nils!
  get 'v1/offline_message', options
end

#person_by_visitor(options = {}) ⇒ Object

Get person_by_visitor



107
108
109
110
111
# File 'lib/comagic_client.rb', line 107

def person_by_visitor(options = {})
  require_auth!
  options.merge!({ session_key: @session_key }).not_nils!
  get 'v1/person_by_visitor', options
end

#respond_to?(method_name, *arguments, &block) ⇒ Boolean

Let class instance respond to post, get, delete, put and patch

Returns:

  • (Boolean)


164
165
166
# File 'lib/comagic_client.rb', line 164

def respond_to?(method_name, *arguments, &block)
  !!method_name.to_s.match(/(post|get|put|patch|delete)/) || super
end

#site(options = {}) ⇒ Object

Get sit(es)



37
38
39
40
41
# File 'lib/comagic_client.rb', line 37

def site(options = {})
  require_auth!
  options.merge!({ session_key: @session_key }).not_nils!
  get 'v1/site', options
end

#stat(options = {}) ⇒ Object

Get stat



65
66
67
68
69
# File 'lib/comagic_client.rb', line 65

def stat(options = {})
  require_auth!
  options.merge!({ session_key: @session_key }).not_nils!
  get 'v1/stat', options
end

#tag(options = {}) ⇒ Object

Get tags



51
52
53
54
55
# File 'lib/comagic_client.rb', line 51

def tag(options = {})
  require_auth!
  options.merge!({ session_key: @session_key }).not_nils!
  get 'v1/tag', options
end

#to_sObject



168
169
170
# File 'lib/comagic_client.rb', line 168

def to_s
  "#{@login}"
end

#visitor(options = {}) ⇒ Object

Get visitor



121
122
123
124
125
# File 'lib/comagic_client.rb', line 121

def visitor(options = {})
  require_auth!
  options.merge!({ session_key: @session_key }).not_nils!
  get 'v1/visitor', options
end

#visitors_by_person(options = {}) ⇒ Object

Get visitors_by_person



114
115
116
117
118
# File 'lib/comagic_client.rb', line 114

def visitors_by_person(options = {})
  require_auth!
  options.merge!({ session_key: @session_key }).not_nils!
  get 'v1/visitors_by_person', options
end