Module: ThrillcallAPI
- Defined in:
- lib/thrillcall-api/result.rb,
lib/thrillcall-api.rb,
lib/thrillcall-api/version.rb,
lib/thrillcall-api/exceptions.rb
Overview
Defined Under Namespace
Constant Summary collapse
- VERSION =
"0.0.6"
Class Attribute Summary collapse
-
.base ⇒ Object
Returns the value of attribute base.
-
.conn ⇒ Object
Returns the value of attribute conn.
-
.cur_api_key ⇒ Object
Returns the value of attribute cur_api_key.
-
.result ⇒ Object
Returns the value of attribute result.
Class Method Summary collapse
- .get(endpoint, params) ⇒ Object
- .method_missing(method, *args, &block) ⇒ Object
-
.new(cur_api_key, options = {}) ⇒ Object
Set up the Faraday connection based on configuration.
- .post(endpoint, params) ⇒ Object
Class Attribute Details
.base ⇒ Object
Returns the value of attribute base.
9 10 11 |
# File 'lib/thrillcall-api.rb', line 9 def base @base end |
.conn ⇒ Object
Returns the value of attribute conn.
9 10 11 |
# File 'lib/thrillcall-api.rb', line 9 def conn @conn end |
.cur_api_key ⇒ Object
Returns the value of attribute cur_api_key.
9 10 11 |
# File 'lib/thrillcall-api.rb', line 9 def cur_api_key @cur_api_key end |
.result ⇒ Object
Returns the value of attribute result.
9 10 11 |
# File 'lib/thrillcall-api.rb', line 9 def result @result end |
Class Method Details
.get(endpoint, params) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/thrillcall-api.rb', line 62 def get(endpoint, params) r = @conn.get do |req| req.url endpoint, params.merge(:api_key => @cur_api_key) end JSON.parse(r.body) end |
.method_missing(method, *args, &block) ⇒ Object
76 77 78 79 80 |
# File 'lib/thrillcall-api.rb', line 76 def method_missing(method, *args, &block) r = Result.new r.send(method, args, block) return r end |
.new(cur_api_key, options = {}) ⇒ Object
Set up the Faraday connection based on configuration
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/thrillcall-api.rb', line 12 def new(cur_api_key, = {}) = { :base_url => "https://api.thrillcall.com/api/", :version => 3, :logger => false, :timeout => 20 } opts = .merge() @cur_api_key = cur_api_key base_url = opts[:base_url] version = opts[:version] logger = opts[:logger] faraday_opts = { :timeout => opts[:timeout], :open_timeout => opts[:timeout] } # Make sure the base_url is in the form https://.../ unless base_url.match /^(http|https):\/\// base_url = "https://" + base_url end unless base_url.match /\/$/ base_url = base_url + "/" end # Set JSON accept header and custom user agent @headers = { :accept => 'application/json', :user_agent => "Thrillcall API Wrapper version #{ThrillcallAPI::VERSION}" } @base = "#{base_url}v#{version}/" @conn = Faraday.new( :url => @base, :headers => @headers, :options => faraday_opts ) do |builder| builder.adapter Faraday.default_adapter if logger builder.response :logger end # This will raise an exception if an error occurs during a request builder.response :raise_error end @result = Result.new return self end |
.post(endpoint, params) ⇒ Object
69 70 71 72 73 74 |
# File 'lib/thrillcall-api.rb', line 69 def post(endpoint, params) r = @conn.post do |req| req.url endpoint, params.merge(:api_key => @cur_api_key) end JSON.parse(r.body) end |