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, &block) ⇒ Object
- #post_xml(path, xml) ⇒ Object
- #service_uri ⇒ Object
Class Method Details
.service_uri ⇒ Object
58 59 60 |
# File 'lib/version-one/client.rb', line 58 def self.service_uri @service_uri ||= get_service_uri end |
Instance Method Details
#cache_store ⇒ Object
50 51 52 |
# File 'lib/version-one/client.rb', line 50 def cache_store VersionOne.cache end |
#can_cache? ⇒ Boolean
54 55 56 |
# File 'lib/version-one/client.rb', line 54 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
46 47 48 |
# File 'lib/version-one/client.rb', line 46 def get_uri(uri, ={}) request :get, uri, end |
#post(path, &block) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/version-one/client.rb', line 32 def post(path, &block) uri = path_uri(path) 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
62 63 64 |
# File 'lib/version-one/client.rb', line 62 def service_uri self.class.service_uri end |