Class: FathomAnalytics::Connection
- Inherits:
-
Object
- Object
- FathomAnalytics::Connection
- Defined in:
- lib/fathom_analytics/connection.rb
Instance Method Summary collapse
- #delete(path: '', auth_token:) ⇒ Object
- #get(path: '', params: {}, auth_token:) ⇒ Object
-
#initialize(base_url:) ⇒ Connection
constructor
A new instance of Connection.
- #post(path: '', params:, auth_token:) ⇒ Object
Constructor Details
#initialize(base_url:) ⇒ Connection
Returns a new instance of Connection.
3 4 5 6 7 8 9 |
# File 'lib/fathom_analytics/connection.rb', line 3 def initialize(base_url:) @base_url = base_url @_fd_connection = Faraday.new( url: @base_url, headers: {'Content-Type' => 'application/json'} ) end |
Instance Method Details
#delete(path: '', auth_token:) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/fathom_analytics/connection.rb', line 31 def delete(path: '', auth_token:) delete_url = @base_url + path @_fd_connection.delete(delete_url) do |req| req.headers['Content-Type'] = 'application/json' req.headers['Cookie'] = "auth=#{auth_token}" if auth_token end end |
#get(path: '', params: {}, auth_token:) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/fathom_analytics/connection.rb', line 11 def get(path: '', params: {}, auth_token:) get_url = @base_url + path @_fd_connection.get(get_url) do |req| params.each do |k, v| req.params[k] = v end req.headers['Content-Type'] = 'application/json' req.headers['Cookie'] = "auth=#{auth_token}" if auth_token end end |
#post(path: '', params:, auth_token:) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/fathom_analytics/connection.rb', line 22 def post(path: '', params:, auth_token:) post_url = @base_url + path @_fd_connection.post(post_url) do |req| req.headers['Content-Type'] = 'application/json' req.headers['Cookie'] = "auth=#{auth_token}" if auth_token req.body = params.to_json end end |