Class: SifiApi::Connection
- Inherits:
-
Object
- Object
- SifiApi::Connection
- Defined in:
- lib/sifi_api/connection.rb
Instance Method Summary collapse
- #delete(user_key, route = '', body = nil, headers = {}) ⇒ Object
- #get(user_key, route = '', params = {}, headers = {}) ⇒ Object
-
#initialize(app_key, site = "https://app.simpli.fi/api/") ⇒ Connection
constructor
A new instance of Connection.
- #post(user_key, route = '', body = nil, headers = {}) ⇒ Object
- #put(user_key, route = '', body = nil, headers = {}) ⇒ Object
- #user(user_key, params = {}) ⇒ Object
Constructor Details
#initialize(app_key, site = "https://app.simpli.fi/api/") ⇒ Connection
Returns a new instance of Connection.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/sifi_api/connection.rb', line 7 def initialize(app_key, site="https://app.simpli.fi/api/") @site = site @app_key = app_key @connection = Faraday::Connection.new(:url => site, :ssl => { :verify => false }) do |builder| builder.use Faraday::Request::ConvertFileToUploadIO builder.request :multipart builder.use Faraday::Request::JsonEncode builder.use Faraday::Response::RaiseSifiError builder.use Faraday::Response::ParseJson builder.adapter Faraday.default_adapter end end |
Instance Method Details
#delete(user_key, route = '', body = nil, headers = {}) ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/sifi_api/connection.rb', line 50 def delete(user_key, route='', body=nil, headers={}) begin response = @connection.run_request(:delete, route, body, { "X-App-Key" => @app_key, "X-User-Key" => user_key }.merge(headers)) response[:status] == 204 rescue Faraday::Error::TimeoutError => e raise SifiApi::Timeout, "Timeout" end end |
#get(user_key, route = '', params = {}, headers = {}) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/sifi_api/connection.rb', line 26 def get(user_key, route='', params={}, headers={}) begin @connection.run_request(:get, @connection.build_url(route, params), nil, { "X-App-Key" => @app_key, "X-User-Key" => user_key }.merge(headers)) rescue Faraday::Error::TimeoutError => e raise SifiApi::Timeout, "Timeout" end end |
#post(user_key, route = '', body = nil, headers = {}) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/sifi_api/connection.rb', line 34 def post(user_key, route='', body=nil, headers={}) begin @connection.run_request(:post, route, body, { "X-App-Key" => @app_key, "X-User-Key" => user_key }.merge(headers)) rescue Faraday::Error::TimeoutError => e raise SifiApi::Timeout, "Timeout" end end |
#put(user_key, route = '', body = nil, headers = {}) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/sifi_api/connection.rb', line 42 def put(user_key, route='', body=nil, headers={}) begin @connection.run_request(:put, route, body, { "X-App-Key" => @app_key, "X-User-Key" => user_key }.merge(headers)) rescue Faraday::Error::TimeoutError => e raise SifiApi::Timeout, "Timeout" end end |
#user(user_key, params = {}) ⇒ Object
22 23 24 |
# File 'lib/sifi_api/connection.rb', line 22 def user(user_key, params={}) SifiApi::User.get_via_uri(self, user_key, '', params).first end |