Module: TumblrWrapper::HTTP
- Included in:
- Resource
- Defined in:
- lib/tumblr_wrapper/http.rb
Instance Method Summary collapse
Instance Method Details
#http_get(path, opts = {signed: false}, params = {}) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/tumblr_wrapper/http.rb', line 3 def http_get(path, opts={signed: false}, params={}) validate_oauth if opts[:signed] connection = Faraday.new TumblrWrapper.endpoint do |conn| conn.request :oauth, access_token if opts[:signed] conn.request :url_encoded conn.response :json, :content_type => /\bjson$/ conn.adapter Faraday.default_adapter end response = if opts[:signed] connection.get(long_path(path), params) else parameters = params.merge({api_key: TumblrWrapper.consumer_key}) connection.get(long_path(path), parameters) end TumblrWrapper::Response.new(response) end |
#http_post(path, body) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/tumblr_wrapper/http.rb', line 21 def http_post(path, body) validate_oauth connection = Faraday.new TumblrWrapper.endpoint do |conn| conn.request :oauth, access_token conn.request :url_encoded conn.response :json, :content_type => /\bjson$/ conn.adapter Faraday.default_adapter end response = connection.post long_path(path), body TumblrWrapper::Response.new(response) end |