Module: Poptart::Request
- Included in:
- BooleanQuestion, Model, MultipleResponseQuestion, Question, RangeQuestion, Survey, SurveyQuestion, SurveyQuestion, TimeQuestion, User, User
- Defined in:
- lib/poptart/request.rb
Instance Method Summary collapse
- #connection ⇒ Object
- #get(url, headers = {}) ⇒ Object
- #post(url, data = {}, headers = {}) ⇒ Object
- #put(url, data, headers = {}) ⇒ Object
Instance Method Details
#connection ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/poptart/request.rb', line 38 def connection return @connection if @connection @connection = Faraday.new(:url => Poptart.url) do |faraday| faraday.request :url_encoded faraday.response :logger faraday.adapter Faraday.default_adapter end end |
#get(url, headers = {}) ⇒ Object
3 4 5 6 7 8 9 10 11 12 |
# File 'lib/poptart/request.rb', line 3 def get(url, headers = {}) connection.get do |req| req.url(url) req.headers['Content-Type'] = 'application/json' req.headers['API-TOKEN'] = Poptart.api_token if Poptart.api_token req.headers['USER-TOKEN'] = Poptart.user_token if Poptart.user_token req.headers['SERVICE-USER-ID'] = Poptart.service_user_id if Poptart.service_user_id req.headers.merge!(headers) end end |
#post(url, data = {}, headers = {}) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/poptart/request.rb', line 26 def post(url, data = {}, headers = {}) connection.post do |req| req.url(url) req.body = data.to_json if data req.headers['Content-Type'] = 'application/json' req.headers['API-TOKEN'] = Poptart.api_token if Poptart.api_token req.headers['USER-TOKEN'] = Poptart.user_token if Poptart.user_token req.headers['SERVICE-USER-ID'] = Poptart.service_user_id if Poptart.service_user_id req.headers.merge!(headers) end end |
#put(url, data, headers = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/poptart/request.rb', line 14 def put(url, data, headers = {}) connection.put do |req| req.url(url) req.body = data.to_json if data req.headers['Content-Type'] = 'application/json' req.headers['API-TOKEN'] = Poptart.api_token if Poptart.api_token req.headers['USER-TOKEN'] = Poptart.user_token if Poptart.user_token req.headers['SERVICE-USER-ID'] = Poptart.service_user_id if Poptart.service_user_id req.headers.merge!(headers) end end |