Class: Satisfaction
- Inherits:
-
Object
- Object
- Satisfaction
- Includes:
- Associations
- Defined in:
- lib/satisfaction.rb
Instance Attribute Summary collapse
-
#consumer ⇒ Object
readonly
Returns the value of attribute consumer.
-
#identity_map ⇒ Object
readonly
Returns the value of attribute identity_map.
-
#loader ⇒ Object
readonly
Returns the value of attribute loader.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #access_token(token) ⇒ Object
- #authorize_url(token) ⇒ Object
- #autoload? ⇒ Boolean
- #delete(path) ⇒ Object
- #get(path, query_string = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Satisfaction
constructor
A new instance of Satisfaction.
- #me ⇒ Object
- #post(path, form = {}) ⇒ Object
- #put(path, form = {}) ⇒ Object
- #request_token ⇒ Object
- #satisfaction ⇒ Object
- #set_basic_auth(user, password) ⇒ Object
- #set_consumer(key, secret) ⇒ Object
- #set_token(token, secret) ⇒ Object
- #url(path, query_string = {}) ⇒ Object
Methods included from Associations
Constructor Details
#initialize(options = {}) ⇒ Satisfaction
Returns a new instance of Satisfaction.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/satisfaction.rb', line 38 def initialize(={}) @options = .reverse_merge({ :root => "http://api.getsatisfaction.com", :autoload => false, :request_token_url => 'http://getsatisfaction.com/api/request_token', :access_token_url => 'http://getsatisfaction.com/api/access_token', :authorize_url => 'http://getsatisfaction.com/api/authorize', }) @loader = Sfn::Loader.new @identity_map = Sfn::IdentityMap.new has_many :companies, :url => '/companies' has_many :people, :url => '/people' has_many :topics, :url => '/topics' has_many :replies, :url => '/replies' has_many :tags, :url => '/tags' has_many :products, :url => '/products' end |
Instance Attribute Details
#consumer ⇒ Object (readonly)
Returns the value of attribute consumer.
33 34 35 |
# File 'lib/satisfaction.rb', line 33 def consumer @consumer end |
#identity_map ⇒ Object (readonly)
Returns the value of attribute identity_map.
35 36 37 |
# File 'lib/satisfaction.rb', line 35 def identity_map @identity_map end |
#loader ⇒ Object (readonly)
Returns the value of attribute loader.
32 33 34 |
# File 'lib/satisfaction.rb', line 32 def loader @loader end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
31 32 33 |
# File 'lib/satisfaction.rb', line 31 def @options end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
34 35 36 |
# File 'lib/satisfaction.rb', line 34 def token @token end |
Instance Method Details
#access_token(token) ⇒ Object
104 105 106 107 108 109 |
# File 'lib/satisfaction.rb', line 104 def access_token(token) result, body = *@loader.get("#{[:access_token_url]}", :force => true, :consumer => @consumer, :token => token) raise "Could not retrieve access token" unless result == :ok response = CGI.parse(body) OAuth::Token.new(response["oauth_token"], response["oauth_token_secret"]) end |
#authorize_url(token) ⇒ Object
100 101 102 |
# File 'lib/satisfaction.rb', line 100 def (token) "#{[:authorize_url]}?oauth_token=#{token.token}" end |
#autoload? ⇒ Boolean
73 74 75 |
# File 'lib/satisfaction.rb', line 73 def autoload? [:autoload] end |
#delete(path) ⇒ Object
136 137 138 139 140 141 142 143 144 |
# File 'lib/satisfaction.rb', line 136 def delete(path) url = self.url(path) @loader.post(url, :consumer => @consumer, :token => @token, :user => @user, :password => @password, :method => :delete) end |
#get(path, query_string = {}) ⇒ Object
119 120 121 122 123 124 |
# File 'lib/satisfaction.rb', line 119 def get(path, query_string={}) url = self.url(path, query_string) @loader.get(url, :consumer => @consumer, :token => @token, :user => @user, :password => @password) end |
#me ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/satisfaction.rb', line 61 def me me = satisfaction.identity_map.get_record(Me, 'me') do Sfn::Me.new('me', satisfaction) end if me.loaded? me else me.load end end |
#post(path, form = {}) ⇒ Object
126 127 128 129 130 131 132 133 134 |
# File 'lib/satisfaction.rb', line 126 def post(path, form={}) url = self.url(path) @loader.post(url, :consumer => @consumer, :token => @token, :user => @user, :password => @password, :form => form) end |
#put(path, form = {}) ⇒ Object
146 147 148 149 150 151 152 153 154 155 |
# File 'lib/satisfaction.rb', line 146 def put(path, form={}) url = self.url(path) @loader.post(url, :consumer => @consumer, :token => @token, :user => @user, :password => @password, :method => :put, :form => form) end |
#request_token ⇒ Object
93 94 95 96 97 98 |
# File 'lib/satisfaction.rb', line 93 def request_token result, body = *@loader.get("#{[:request_token_url]}", :force => true, :consumer => @consumer, :token => nil) raise "Could not retrieve request token" unless result == :ok response = CGI.parse(body) OAuth::Token.new(response["oauth_token"], response["oauth_token_secret"]) end |
#satisfaction ⇒ Object
57 58 59 |
# File 'lib/satisfaction.rb', line 57 def satisfaction self end |
#set_basic_auth(user, password) ⇒ Object
77 78 79 80 81 |
# File 'lib/satisfaction.rb', line 77 def set_basic_auth(user, password) identity_map.expire_record(Me, 'me') @user = user @password = password end |
#set_consumer(key, secret) ⇒ Object
83 84 85 86 |
# File 'lib/satisfaction.rb', line 83 def set_consumer(key, secret) identity_map.expire_record(Me, 'me') @consumer = OAuth::Consumer.new(key, secret) end |
#set_token(token, secret) ⇒ Object
88 89 90 91 |
# File 'lib/satisfaction.rb', line 88 def set_token(token, secret) identity_map.expire_record(Me, 'me') @token = OAuth::Token.new(token, secret) end |
#url(path, query_string = {}) ⇒ Object
112 113 114 115 116 117 |
# File 'lib/satisfaction.rb', line 112 def url(path, query_string={}) qs = query_string.map{|kv| URI.escape(kv.first.to_s) + "=" + URI.escape(kv.last.to_s)}.join("&") uri_string = "#{@options[:root]}#{path}" uri_string += "?#{qs}" unless qs.blank? URI.parse(uri_string) end |