Class: SnoozeForce::Client
- Inherits:
-
Object
- Object
- SnoozeForce::Client
- Includes:
- HTTParty
- Defined in:
- lib/snooze_force/client.rb
Instance Attribute Summary collapse
-
#client_id ⇒ Object
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
Returns the value of attribute client_secret.
-
#instance_url ⇒ Object
Returns the value of attribute instance_url.
-
#options ⇒ Object
Returns the value of attribute options.
-
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
-
#token ⇒ Object
Returns the value of attribute token.
-
#uid ⇒ Object
Returns the value of attribute uid.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #query(q = '', options = {}) ⇒ Object
- #rebuild_sobjects! ⇒ Object
- #refresh! ⇒ Object
- #search(q = '', options = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/snooze_force/client.rb', line 13 def initialize( = {}) self.instance_url = [:instance_url] self.token = [:token] self.uid = [:uid] self.refresh_token = [:refresh_token] self.client_id = [:client_id] self.client_secret = [:client_secret] self. = {:headers => {'Content-Type' => 'application/json'}}.merge() self.rebuild_sobjects! if self.uid end |
Instance Attribute Details
#client_id ⇒ Object
Returns the value of attribute client_id.
9 10 11 |
# File 'lib/snooze_force/client.rb', line 9 def client_id @client_id end |
#client_secret ⇒ Object
Returns the value of attribute client_secret.
10 11 12 |
# File 'lib/snooze_force/client.rb', line 10 def client_secret @client_secret end |
#instance_url ⇒ Object
Returns the value of attribute instance_url.
5 6 7 |
# File 'lib/snooze_force/client.rb', line 5 def instance_url @instance_url end |
#options ⇒ Object
Returns the value of attribute options.
11 12 13 |
# File 'lib/snooze_force/client.rb', line 11 def @options end |
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
8 9 10 |
# File 'lib/snooze_force/client.rb', line 8 def refresh_token @refresh_token end |
#token ⇒ Object
Returns the value of attribute token.
6 7 8 |
# File 'lib/snooze_force/client.rb', line 6 def token @token end |
#uid ⇒ Object
Returns the value of attribute uid.
7 8 9 |
# File 'lib/snooze_force/client.rb', line 7 def uid @uid end |
Instance Method Details
#query(q = '', options = {}) ⇒ Object
62 63 64 |
# File 'lib/snooze_force/client.rb', line 62 def query(q = '', = {}) self.get("/query?q=#{URI.escape(q)}", ) end |
#rebuild_sobjects! ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/snooze_force/client.rb', line 26 def rebuild_sobjects! # Let's build all the available classes for this uid: res = self.get('sobjects') res['sobjects'].each do |sobject| name = sobject['name'] eval <<-EOF module ::SnoozeForce module U#{self.uid} class #{name} < ::SnoozeForce::Base def initialize(client, options = {}) super self.base = '#{name}' end end end end def self.#{name.underscore} unless @_#{name.underscore} @_#{name.underscore} = ::SnoozeForce::U#{self.uid}::#{name}.new(self) end return @_#{name.underscore} end EOF "::SnoozeForce::U#{self.uid}::#{name}".constantize.sobject = sobject "::SnoozeForce::U#{self.uid}::#{name}".constantize.send(:include, "::SnoozeForce::#{name}".constantize) if SnoozeForce.const_defined?(name) end end |
#refresh! ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/snooze_force/client.rb', line 54 def refresh! response = HTTParty.post("https://login.salesforce.com/services/oauth2/token?grant_type=refresh_token&client_id=#{self.client_id}&client_secret=#{self.client_secret}&refresh_token=#{self.refresh_token}") raise SnoozeForce::ResponseError.new(response.code, response['error_description']) if response.code != 200 self.token = response['access_token'] self.instance_url = response['instance_url'] response end |
#search(q = '', options = {}) ⇒ Object
66 67 68 |
# File 'lib/snooze_force/client.rb', line 66 def search(q = '', = {}) self.get("/search?q=#{URI.escape(q)}", ) end |