Class: VersionOne::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/version-one/client.rb

Constant Summary collapse

XML_CONTENT_TYPE =
'text/xml'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.get_service_uriObject



61
62
63
64
# File 'lib/version-one/client.rb', line 61

def self.get_service_uri
  raise "VersionOne service_uri must be configured" unless VersionOne.config.service_uri
  URI.parse(VersionOne.config.service_uri)
end

.service_uriObject



51
52
53
# File 'lib/version-one/client.rb', line 51

def self.service_uri
  @service_uri ||= get_service_uri
end

Instance Method Details

#cache_storeObject



43
44
45
# File 'lib/version-one/client.rb', line 43

def cache_store
  #Rails.cache
end

#can_cache?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/version-one/client.rb', line 47

def can_cache?
  @cache && cache_store
end

#get(path, *fields) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/version-one/client.rb', line 10

def get(path, *fields)
  uri = path_uri(path)

  unless fields.empty?
    fields.concat(Query::REQUIRED_FIELDS)
    uri.query = "sel=#{fields.join(',')}"
  end

  get_uri uri
end

#get_uri(uri) ⇒ Object



39
40
41
# File 'lib/version-one/client.rb', line 39

def get_uri(uri)
  request :get, uri
end

#post(path) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/version-one/client.rb', line 31

def post(path)
  uri = path_uri(path)
  request :post, uri do |r|
    r.body = ''
    r.content_type = XML_CONTENT_TYPE
  end
end

#post_xml(path, xml) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/version-one/client.rb', line 21

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_uriObject



55
56
57
# File 'lib/version-one/client.rb', line 55

def service_uri
  self.class.service_uri
end