Class: Typeform::Connection
- Inherits:
-
Object
- Object
- Typeform::Connection
- Defined in:
- lib/typeform/connection.rb
Constant Summary collapse
- @@base_uri =
"https://api.typeform.io"
Instance Method Summary collapse
- #get(path) ⇒ Object
-
#initialize(api_key) ⇒ Connection
constructor
A new instance of Connection.
- #post(path, body) ⇒ Object
- #set_base_headers(request) ⇒ Object
Constructor Details
#initialize(api_key) ⇒ Connection
Returns a new instance of Connection.
5 6 7 8 9 10 11 12 13 |
# File 'lib/typeform/connection.rb', line 5 def initialize(api_key) @api_key = api_key @conn = Faraday.new(url: @@base_uri) do |faraday| faraday.request :json faraday.response :logger faraday.adapter Faraday.default_adapter faraday.use FaradayMiddleware::ParseJson, :content_type => /\bjson$/ end end |
Instance Method Details
#get(path) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/typeform/connection.rb', line 21 def get(path) @conn.get do |request| set_base_headers(request) request.url "/v0.3#{path}" end end |
#post(path, body) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/typeform/connection.rb', line 28 def post(path, body) @conn.post do |request| set_base_headers(request) request.url "/v0.3#{path}" request.body = body end end |
#set_base_headers(request) ⇒ Object
15 16 17 18 19 |
# File 'lib/typeform/connection.rb', line 15 def set_base_headers(request) request.headers["X-API-TOKEN"] = @api_key request.headers["Content-Type"] = "application/json; charset=utf-8" request.headers["Accept-Encoding"] = "gzip, deflate" end |