class Pinterest::Client
Constants
- BASE_ENDPOINT
- DEFAULT_ADAPTER
- DEFAULT_USER_AGENT
Attributes
access_token[R]
Public Class Methods
new(access_token = nil, connection_options={})
click to toggle source
# File lib/pinterest/client.rb, line 17 def initialize(access_token = nil, connection_options={}) @access_token = access_token @connection_options = connection_options end
Public Instance Methods
delete(path, options={})
click to toggle source
# File lib/pinterest/client.rb, line 40 def delete(path, options={}) request(:delete, path, options) end
get(path, options={})
click to toggle source
# File lib/pinterest/client.rb, line 24 def get(path, options={}) request(:get, path, options) end
patch(path, options={})
click to toggle source
# File lib/pinterest/client.rb, line 32 def patch(path, options={}) request(:patch, path, options) end
post(path, options={})
click to toggle source
# File lib/pinterest/client.rb, line 28 def post(path, options={}) request(:post, path, options) end
put(path, options={})
click to toggle source
# File lib/pinterest/client.rb, line 36 def put(path, options={}) request(:put, path, options) end
Private Instance Methods
adapter()
click to toggle source
# File lib/pinterest/client.rb, line 94 def adapter DEFAULT_ADAPTER end
connection(raw = false, log = false)
click to toggle source
# File lib/pinterest/client.rb, line 68 def connection(raw = false, log = false) options = @connection_options.merge({ :headers => {'Accept' => "application/json; charset=utf-8", 'User-Agent' => user_agent}, :url => endpoint, }) Faraday::Connection.new(options) do |connection| unless raw connection.use FaradayMiddleware::Mashify end connection.use Faraday::Request::Multipart connection.use Faraday::Response::ParseJson connection.use Faraday::Request::UrlEncoded connection.response :logger if log connection.adapter(adapter) end end
endpoint()
click to toggle source
# File lib/pinterest/client.rb, line 86 def endpoint BASE_ENDPOINT end
request(method, path, options)
click to toggle source
# File lib/pinterest/client.rb, line 46 def request(method, path, options) raw = options.delete(:raw) log = options.delete(:log) path = File.join(path, '') response = connection(raw, log).send(method) do |request| case method when :get path = path + "?access_token=" + @access_token request.url(URI.encode(path), options) when :patch request.path = path + "?access_token=" + @access_token request.body = options unless options.empty? request.headers['Authorization'] = "BEARER #{@access_token}" when :post, :put, :delete request.path = URI.encode(path) request.body = options unless options.empty? request.headers['Authorization'] = "BEARER #{@access_token}" end end return response.body end
user_agent()
click to toggle source
# File lib/pinterest/client.rb, line 90 def user_agent DEFAULT_USER_AGENT end