Class: VersionOne::Client
- Inherits:
-
Object
- Object
- VersionOne::Client
- Defined in:
- lib/version-one/client.rb
Constant Summary collapse
- XML_CONTENT_TYPE =
'text/xml'
Class Method Summary collapse
Instance Method Summary collapse
- #cache_store ⇒ Object
- #can_cache? ⇒ Boolean
- #get(path, *fields) ⇒ Object
- #get_uri(uri, options = {}) ⇒ Object
- #post(path, query = {}, &block) ⇒ Object
- #post_xml(path, xml) ⇒ Object
- #service_uri ⇒ Object
Class Method Details
.service_uri ⇒ Object
61 62 63 |
# File 'lib/version-one/client.rb', line 61 def self.service_uri @service_uri ||= get_service_uri end |
Instance Method Details
#cache_store ⇒ Object
53 54 55 |
# File 'lib/version-one/client.rb', line 53 def cache_store VersionOne.cache end |
#can_cache? ⇒ Boolean
57 58 59 |
# File 'lib/version-one/client.rb', line 57 def can_cache? !!cache_store end |
#get(path, *fields) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/version-one/client.rb', line 10 def get(path, *fields) uri = path_uri(path) = fields.last.is_a?(Hash) ? fields.pop : {} unless fields.empty? fields.concat(Query::REQUIRED_FIELDS) uri.query = "sel=#{fields.join(',')}" end get_uri uri, end |
#get_uri(uri, options = {}) ⇒ Object
49 50 51 |
# File 'lib/version-one/client.rb', line 49 def get_uri(uri, ={}) request :get, uri, end |
#post(path, query = {}, &block) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/version-one/client.rb', line 32 def post(path, query={}, &block) uri = path_uri(path) if query && !query.empty? uri.query = URI.encode_www_form(query) end if block_given? request :post, uri, &block else request :post, uri do |r| r.body = '' r.content_type = XML_CONTENT_TYPE end end end |
#post_xml(path, xml) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/version-one/client.rb', line 22 def post_xml(path, xml) uri = path_uri(path) xml = xml.root if xml.respond_to?(:root) xml.attributes['href'] = uri.path request :post, uri do |r| r.body = xml.to_s r.content_type = XML_CONTENT_TYPE end end |
#service_uri ⇒ Object
65 66 67 |
# File 'lib/version-one/client.rb', line 65 def service_uri self.class.service_uri end |