Class: ComagicClient
- Inherits:
-
Object
- Object
- ComagicClient
- Defined in:
- lib/comagic_client.rb
Overview
This class creates a new comagic connector instanse
Defined Under Namespace
Classes: ApiError
Instance Method Summary collapse
-
#ac(options = {}) ⇒ Object
Get ad campaigns.
-
#call(options = {}) ⇒ Object
Get call.
-
#chat(options = {}) ⇒ Object
Get chat.
-
#chat_message(options = {}) ⇒ Object
Get chat_message.
-
#communication(options = {}) ⇒ Object
Get communications.
- #create_site(options = {}) ⇒ Object
-
#customer_list(options = {}) ⇒ Object
Get customer_list.
-
#get_cdr_in(options = {}) ⇒ Object
Get get_cdr_in.
-
#get_cdr_out(options = {}) ⇒ Object
Get get_cdr_out.
-
#goal(options = {}) ⇒ Object
Get goal.
-
#initialize(login, password) ⇒ ComagicClient
constructor
Set up a new connector instanse.
-
#login ⇒ Object
Perform login with login and password specified in the initialize method.
-
#logout ⇒ Object
Perform logout.
-
#method_missing(method_name, *arguments, &block) ⇒ Object
Pass post, get, delete, put and patch to the request method.
-
#offline_message(options = {}) ⇒ Object
Get offline_message.
-
#person_by_visitor(options = {}) ⇒ Object
Get person_by_visitor.
-
#respond_to?(method_name, *arguments, &block) ⇒ Boolean
Let class instance respond to post, get, delete, put and patch.
-
#site(options = {}) ⇒ Object
Get sit(es).
-
#stat(options = {}) ⇒ Object
Get stat.
-
#tag(options = {}) ⇒ Object
Get tags.
- #to_s ⇒ Object
-
#visitor(options = {}) ⇒ Object
Get visitor.
-
#visitors_by_person(options = {}) ⇒ Object
Get visitors_by_person.
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(login, password) @session_key = nil @api_url = 'http://api.comagic.ru/api' @login, @password = login, 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( = {}) require_auth! .merge!({ session_key: @session_key }).not_nils! get 'v1/ac', end |
#call(options = {}) ⇒ Object
Get call
79 80 81 82 83 |
# File 'lib/comagic_client.rb', line 79 def call( = {}) require_auth! .merge!({ session_key: @session_key }).not_nils! get 'v1/call', end |
#chat(options = {}) ⇒ Object
Get chat
86 87 88 89 90 |
# File 'lib/comagic_client.rb', line 86 def chat( = {}) require_auth! .merge!({ session_key: @session_key }).not_nils! get 'v1/chat', end |
#chat_message(options = {}) ⇒ Object
Get chat_message
93 94 95 96 97 |
# File 'lib/comagic_client.rb', line 93 def ( = {}) require_auth! .merge!({ session_key: @session_key }).not_nils! get 'v1/chat_message', end |
#communication(options = {}) ⇒ Object
Get communications
58 59 60 61 62 |
# File 'lib/comagic_client.rb', line 58 def communication( = {}) require_auth! .merge!({ session_key: @session_key }).not_nils! get 'v1/communication', end |
#create_site(options = {}) ⇒ Object
148 149 150 151 152 |
# File 'lib/comagic_client.rb', line 148 def create_site( = {}) require_auth! .merge!({ session_key: @session_key }).not_nils! post 'v1/create_site', end |
#customer_list(options = {}) ⇒ Object
Get customer_list
142 143 144 145 146 |
# File 'lib/comagic_client.rb', line 142 def customer_list( = {}) require_auth! .merge!({ session_key: @session_key }).not_nils! get 'v1/customer_list', 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( = {}) require_auth! .merge!({ session_key: @session_key }).not_nils! get 'v1/get_cdr_in', 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( = {}) require_auth! .merge!({ session_key: @session_key }).not_nils! get 'v1/get_cdr_out', end |
#goal(options = {}) ⇒ Object
Get goal
72 73 74 75 76 |
# File 'lib/comagic_client.rb', line 72 def goal( = {}) require_auth! .merge!({ session_key: @session_key }).not_nils! get 'v1/goal', end |
#login ⇒ Object
Perform login with login and password specified in the initialize method
24 25 26 27 |
# File 'lib/comagic_client.rb', line 24 def login response = post "login", login: @login, password: @password @session_key = response['session_key'] end |
#logout ⇒ Object
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 ( = {}) require_auth! .merge!({ session_key: @session_key }).not_nils! get 'v1/offline_message', 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( = {}) require_auth! .merge!({ session_key: @session_key }).not_nils! get 'v1/person_by_visitor', end |
#respond_to?(method_name, *arguments, &block) ⇒ Boolean
Let class instance respond to post, get, delete, put and patch
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( = {}) require_auth! .merge!({ session_key: @session_key }).not_nils! get 'v1/site', end |
#stat(options = {}) ⇒ Object
Get stat
65 66 67 68 69 |
# File 'lib/comagic_client.rb', line 65 def stat( = {}) require_auth! .merge!({ session_key: @session_key }).not_nils! get 'v1/stat', end |
#tag(options = {}) ⇒ Object
Get tags
51 52 53 54 55 |
# File 'lib/comagic_client.rb', line 51 def tag( = {}) require_auth! .merge!({ session_key: @session_key }).not_nils! get 'v1/tag', end |
#to_s ⇒ Object
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( = {}) require_auth! .merge!({ session_key: @session_key }).not_nils! get 'v1/visitor', 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( = {}) require_auth! .merge!({ session_key: @session_key }).not_nils! get 'v1/visitors_by_person', end |