Module: Telapi::Network

Includes:
HTTParty
Included in:
Resource
Defined in:
lib/telapi/network.rb

Overview

Internal object for network operations; wraps HTTParty

Class Method Summary collapse

Class Method Details

.api_uri(path_components = []) ⇒ Object

path_components is an array of uri fragments, e.g [‘Calls’, ‘1234abc’]



24
25
26
# File 'lib/telapi/network.rb', line 24

def api_uri(path_components=[])
  [ Telapi.config.base_uri, 'Accounts', Telapi.config., path_components ].flatten.join('/') + response_format
end

.default_optionsObject



32
33
34
35
36
37
38
39
40
# File 'lib/telapi/network.rb', line 32

def default_options
  {
    :basic_auth => {
      :username => (Telapi.config. || raise(InvalidConfiguration, 'account_sid')),
      :password => (Telapi.config.auth_token  || raise(InvalidConfiguration, 'auth_token'))
    },
    :ssl_ca_path => Telapi.config.ssl_ca_path
  }
end

.delete(path_components = []) ⇒ Object



19
20
21
# File 'lib/telapi/network.rb', line 19

def delete(path_components=[])
  handle_response(HTTParty.delete api_uri(path_components), default_options)
end

.get(path_components = [], query = nil) ⇒ Object



9
10
11
12
# File 'lib/telapi/network.rb', line 9

def get(path_components=[], query=nil)
  options = default_options.merge(:query => query)
  handle_response(HTTParty.get api_uri(path_components), options)
end

.post(path_components = [], body) ⇒ Object



14
15
16
17
# File 'lib/telapi/network.rb', line 14

def post(path_components=[], body)
  options = default_options.merge(:body => body)
  handle_response(HTTParty.post api_uri(path_components), options)
end

.response_formatObject



28
29
30
# File 'lib/telapi/network.rb', line 28

def response_format
  @api_format ||= '.json'
end