class TroveOAuth::Client
Public Class Methods
new(options = {})
click to toggle source
# File lib/trove_oauth/client.rb, line 4 def initialize(options = {}) @consumer_key = options[:consumer_key] @consumer_secret = options[:consumer_secret] @token = options[:token] @secret = options[:secret] @proxy = options[:proxy] end
Public Instance Methods
access_token()
click to toggle source
# File lib/trove_oauth/client.rb, line 42 def access_token @access_token ||= OAuth::AccessToken.new(consumer, @token, @secret) end
add_photo(photo)
click to toggle source
# File lib/trove_oauth/photos.rb, line 4 def add_photo(photo) raise InternalError.new("Supplied photo must be of type TroveOAuth::Photo") unless photo.is_a? Photo end
authentication_request_token(options={})
click to toggle source
# File lib/trove_oauth/client.rb, line 35 def authentication_request_token(options={}) consumer.options[:authorize_path] = '/oauth/authenticate' request_token(options) end
evil_send(method, params)
click to toggle source
# File lib/trove_oauth/account.rb, line 7 def evil_send(method, params) self.send(method, *params) end
info()
click to toggle source
# File lib/trove_oauth/account.rb, line 3 def info get("/v2/user/") end
list_photos(params = {})
click to toggle source
# File lib/trove_oauth/photos.rb, line 11 def list_photos(params = {}) if params[:query_object] else params[:tags] = params[:tags].join(',') if params[:tags].is_a? Array params[:services] = params[:services].join(',') if params[:services].is_a? Array query_string = params.map{|k,v| "#{CGI.escape(k)}=#{CGI.escape(v)}"}.join("&") get("/v2/content/photos/?#{query_string}") end end
request_token(options={})
click to toggle source
# File lib/trove_oauth/client.rb, line 31 def request_token(options={}) consumer.get_request_token(options) end
service(service)
click to toggle source
# File lib/trove_oauth/services.rb, line 7 def service(service) get("/v2/services/#{service}/") end
service_bounceback_url(service, redirect_url)
click to toggle source
# File lib/trove_oauth/services.rb, line 11 def service_bounceback_url(service, redirect_url) SITE + get_without_json("/v2/services/#{service}/bounceback") end
services()
click to toggle source
# File lib/trove_oauth/services.rb, line 3 def services get("/v2/services/") end
show(username)
click to toggle source
# File lib/trove_oauth/client.rb, line 22 def show(username) get("/users/show/#{username}.json") end
test()
click to toggle source
Returns the string “ok” in the requested format with a 200 OK HTTP status code.
# File lib/trove_oauth/client.rb, line 27 def test get("/help/test.json") end
Private Instance Methods
consumer()
click to toggle source
# File lib/trove_oauth/client.rb, line 49 def consumer @consumer = OAuth::Consumer.new(@consumer_key, @consumer_secret, :site => API, :authorize_path => '/oauth/authorize/', :access_token_path => SITE + '/oauth/access_token/', :request_token_path => '/oauth/request_token/', :http_method => :get, :signature_method => 'PLAINTEXT', :scheme=> :query_string) end
delete(path, headers={})
click to toggle source
# File lib/trove_oauth/client.rb, line 84 def delete(path, headers={}) headers.merge!("User-Agent" => "trove_oauth gem v#{TroveOAuth::VERSION}") oauth_response = access_token.delete("/1#{path}", headers) JSON.parse(oauth_response.body) end
get(path, headers={})
click to toggle source
# File lib/trove_oauth/client.rb, line 61 def get(path, headers={}) headers.merge!("User-Agent" => "trove_oauth gem v#{TroveOAuth::VERSION}") oauth_response = access_token.get(path, headers) JSON.parse(oauth_response.body) end
get_without_json(path, headers={})
click to toggle source
# File lib/trove_oauth/client.rb, line 67 def get_without_json(path, headers={}) headers.merge!("User-Agent" => "trove_oauth gem v#{TroveOAuth::VERSION}") oauth_response = access_token.get(path, headers) oauth_response.body end
post(path, body='', headers={})
click to toggle source
# File lib/trove_oauth/client.rb, line 73 def post(path, body='', headers={}) headers.merge!("User-Agent" => "trove_oauth gem v#{TroveOAuth::VERSION}") oauth_response = access_token.post("/1#{path}", body, headers) JSON.parse(oauth_response.body) end
post_without_json(path, body='', headers={})
click to toggle source
# File lib/trove_oauth/client.rb, line 79 def post_without_json(path, body='', headers={}) headers.merge!("User-Agent" => "trove_oauth gem v#{TroveOAuth::VERSION}") access_token.post("/1#{path}", body, headers).body end