Class: Xignite::Service
- Inherits:
-
Object
- Object
- Xignite::Service
- Extended by:
- Helpers
- Includes:
- Helpers
- Defined in:
- lib/xignite/service.rb
Direct Known Subclasses
Class Attribute Summary collapse
-
.options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(curl_response = nil) ⇒ Service
constructor
A new instance of Service.
Methods included from Helpers
Constructor Details
#initialize(curl_response = nil) ⇒ Service
Returns a new instance of Service.
56 57 58 59 60 61 62 63 64 |
# File 'lib/xignite/service.rb', line 56 def initialize(curl_response=nil) return if curl_response.nil? Crack::XML.parse(curl_response.body_str).each do |klass, data| data = weed(data) Xignite.const_set(klass, Class.new(Xignite.const_get(data.class.to_s))) unless Xignite.const_defined?(klass) instance_variable_set("@#{underscore(klass)}", Xignite.const_get(klass).build(data, self.class.)) instance_eval "def #{underscore(klass)} ; @#{underscore(klass)} ; end" end end |
Class Attribute Details
.options ⇒ Object
Returns the value of attribute options.
7 8 9 |
# File 'lib/xignite/service.rb', line 7 def @options end |
Class Method Details
.get(options = {}) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/xignite/service.rb', line 19 def get(={}) = .merge('Header_Username' => Xignite.configuration.username) if Xignite.configuration.username querystring = .map do |key, value| "#{CGI.escape(key.to_s).gsub(/%(5B|5D)/n) { [$1].pack('H*') }}=#{CGI.escape(value)}" end.sort * '&' response = Curl::Easy.http_get([endpoint, querystring].reject{|s| s == '' }.join('?')) new(response) end |
.post(options = {}) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/xignite/service.rb', line 9 def post(={}) response = Curl::Easy.http_post(endpoint, *[].tap do |postbody| postbody << Curl::PostField.content('Header_Username', Xignite.configuration.username) if Xignite.configuration.username .each do |key, value| postbody << Curl::PostField.content(key, value) end end) new(response) end |