Class: Partigirb::Client
Defined Under Namespace
Classes: Request
Constant Summary collapse
- VALID_METHODS =
[:get,:post,:put,:delete]
- VALID_FORMATS =
[:atom,:xml,:json]
- PARTIGI_API_HOST =
"www.partigi.com"- TIMESTAMP_FORMAT =
'%Y-%m-%dT%H:%M:%SZ'
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#api_host ⇒ Object
Returns the value of attribute api_host.
-
#api_version ⇒ Object
Returns the value of attribute api_version.
-
#auth ⇒ Object
Returns the value of attribute auth.
-
#consumer_key ⇒ Object
Returns the value of attribute consumer_key.
-
#consumer_secret ⇒ Object
Returns the value of attribute consumer_secret.
-
#default_format ⇒ Object
Returns the value of attribute default_format.
-
#handlers ⇒ Object
Returns the value of attribute handlers.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#request ⇒ Object
Returns the value of attribute request.
-
#transport ⇒ Object
Returns the value of attribute transport.
Instance Method Summary collapse
- #authorize_from_access(token, secret) ⇒ Object
-
#authorize_from_request(request_token, request_secret, verifier_or_pin) ⇒ Object
For web apps use params, for desktop apps, use the verifier is the pin that twitter gives users.
-
#clear ⇒ Object
Clears any pending request built up by chained methods but not executed.
- #consumer ⇒ Object
-
#initialize(consumer_key, consumer_secret, options = {}) ⇒ Client
constructor
A new instance of Client.
- #method_missing(name, *args) ⇒ Object
-
#request_token(options = {}) ⇒ Object
Note: If using oauth with a web app, be sure to provide :oauth_callback.
- #set_callback_url(url) ⇒ Object
-
#verify_credentials ⇒ Object
Shortcut methods.
Constructor Details
#initialize(consumer_key, consumer_secret, options = {}) ⇒ Client
Returns a new instance of Client.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/partigirb/client.rb', line 51 def initialize(consumer_key, consumer_secret, ={}) @consumer = ::OAuth::Consumer.new(consumer_key, consumer_secret, {:site => "http://#{PARTIGI_API_HOST}"}) @transport = Transport.new(@consumer) @api_host = PARTIGI_API_HOST.clone @api_version = [:api_version] || Partigirb::CURRENT_API_VERSION @headers = {"User-Agent"=>"Partigirb/#{Partigirb::VERSION}"}.merge!([:headers]||{}) @default_format = [:default_format] || :atom @handlers = { :json => Partigirb::Handlers::JSONHandler.new, :xml => Partigirb::Handlers::XMLHandler.new, :atom => Partigirb::Handlers::AtomHandler.new, :unknown => Partigirb::Handlers::StringHandler.new } @handlers.merge!([:handlers]) if [:handlers] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/partigirb/client.rb', line 67 def method_missing(name,*args) # If method is a format name, execute using that format if format_invocation?(name) return call_with_format(name,*args) end # If method ends in ! or ? use that to determine post or get if name.to_s =~ /^(.*)(!|\?)$/ name = $1.to_sym # ! is a post, ? is a get self.request.method = ($2 == '!' ? :post : :get) if format_invocation?(name) return call_with_format(name,*args) else self.request << "/#{$1}" return call_with_format(self.default_format,*args) end end # Else add to the request path self.request << "/#{name}" self end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
49 50 51 |
# File 'lib/partigirb/client.rb', line 49 def access_token @access_token end |
#api_host ⇒ Object
Returns the value of attribute api_host.
49 50 51 |
# File 'lib/partigirb/client.rb', line 49 def api_host @api_host end |
#api_version ⇒ Object
Returns the value of attribute api_version.
49 50 51 |
# File 'lib/partigirb/client.rb', line 49 def api_version @api_version end |
#auth ⇒ Object
Returns the value of attribute auth.
49 50 51 |
# File 'lib/partigirb/client.rb', line 49 def auth @auth end |
#consumer_key ⇒ Object
Returns the value of attribute consumer_key.
49 50 51 |
# File 'lib/partigirb/client.rb', line 49 def consumer_key @consumer_key end |
#consumer_secret ⇒ Object
Returns the value of attribute consumer_secret.
49 50 51 |
# File 'lib/partigirb/client.rb', line 49 def consumer_secret @consumer_secret end |
#default_format ⇒ Object
Returns the value of attribute default_format.
49 50 51 |
# File 'lib/partigirb/client.rb', line 49 def default_format @default_format end |
#handlers ⇒ Object
Returns the value of attribute handlers.
49 50 51 |
# File 'lib/partigirb/client.rb', line 49 def handlers @handlers end |
#headers ⇒ Object
Returns the value of attribute headers.
49 50 51 |
# File 'lib/partigirb/client.rb', line 49 def headers @headers end |
#request ⇒ Object
Returns the value of attribute request.
49 50 51 |
# File 'lib/partigirb/client.rb', line 49 def request @request end |
#transport ⇒ Object
Returns the value of attribute transport.
49 50 51 |
# File 'lib/partigirb/client.rb', line 49 def transport @transport end |
Instance Method Details
#authorize_from_access(token, secret) ⇒ Object
125 126 127 |
# File 'lib/partigirb/client.rb', line 125 def (token, secret) @access_token = OAuth::AccessToken.new(consumer, token, secret) end |
#authorize_from_request(request_token, request_secret, verifier_or_pin) ⇒ Object
For web apps use params, for desktop apps, use the verifier is the pin that twitter gives users.
112 113 114 115 |
# File 'lib/partigirb/client.rb', line 112 def (request_token, request_secret, verifier_or_pin) request_token = OAuth::RequestToken.new(consumer, request_token, request_secret) @access_token = request_token.get_access_token(:oauth_verifier => verifier_or_pin) end |
#clear ⇒ Object
Clears any pending request built up by chained methods but not executed
90 91 92 |
# File 'lib/partigirb/client.rb', line 90 def clear self.request = nil end |
#consumer ⇒ Object
117 118 119 |
# File 'lib/partigirb/client.rb', line 117 def consumer @consumer end |
#request_token(options = {}) ⇒ Object
Note: If using oauth with a web app, be sure to provide :oauth_callback.
101 102 103 |
# File 'lib/partigirb/client.rb', line 101 def request_token(={}) @request_token ||= consumer.get_request_token() end |
#set_callback_url(url) ⇒ Object
105 106 107 108 |
# File 'lib/partigirb/client.rb', line 105 def set_callback_url(url) clear_request_token request_token(:oauth_callback => url) end |
#verify_credentials ⇒ Object
Shortcut methods
131 132 133 |
# File 'lib/partigirb/client.rb', line 131 def verify_credentials account.verify_credentials? end |