Class: RubyVibe::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(auth_token:) ⇒ Client

Returns a new instance of Client.



9
10
11
12
13
# File 'lib/ruby_vibe/client.rb', line 9

def initialize(auth_token:) 
  RubyVibe.configure

  @token = auth_token || RubyVibe.config.auth_token
end

Instance Attribute Details

#tokenObject

Returns the value of attribute token.



7
8
9
# File 'lib/ruby_vibe/client.rb', line 7

def token
  @token
end

Instance Method Details

#action(url, payload: {}, http_method: :post) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ruby_vibe/client.rb', line 15

def action(url, payload: {}, http_method: :post)
  headers = {
    'User-Agent': "RubyVibe client v#{RubyVibe::VERSION})",
    'X-Viber-Auth-Token': token 
  }

  response = ::RestClient::Request.execute(
    method:     http_method, 
    url:        url,
    payload:    payload.to_json, 
    headers:    headers,
    timeout:    5, 
    verify_ssl: ::OpenSSL::SSL::VERIFY_NONE
  )
  
  return_response(response)
end