Module: Datmachine

Defined in:
lib/datmachine.rb,
lib/datmachine/error.rb,
lib/datmachine/pager.rb,
lib/datmachine/utils.rb,
lib/datmachine/client.rb,
lib/datmachine/version.rb,
lib/datmachine/resources/plan.rb,
lib/datmachine/resources/customer.rb,
lib/datmachine/resources/resource.rb,
lib/datmachine/resources/subscription.rb

Defined Under Namespace

Modules: Resource, Utils Classes: BadGateway, BadRequest, Client, Conflict, Customer, Error, Forbidden, GatewayTimeout, Gone, InternalServerError, MethodNotAllowed, MoreInformationRequired, NotFound, NotImplemented, Pager, PaymentRequired, Plan, ServiceUnavailable, StandardError, Subscription, Unauthorized

Constant Summary collapse

VERSION =
'1.0.0'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.clientObject

Returns the value of attribute client.



24
25
26
# File 'lib/datmachine.rb', line 24

def client
  @client
end

.configObject

Returns the value of attribute config.



25
26
27
# File 'lib/datmachine.rb', line 25

def config
  @config
end

.hypermedia_registryObject

Returns the value of attribute hypermedia_registry.



26
27
28
# File 'lib/datmachine.rb', line 26

def hypermedia_registry
  @hypermedia_registry
end

Class Method Details

.configure(api_key = nil, site_id = nil, options = {}) ⇒ Object



28
29
30
31
# File 'lib/datmachine.rb', line 28

def configure(api_key=nil, site_id=nil, options={})
  @config = @config.merge(options)
  @client = Datmachine::Client.new(api_key, site_id, @config)
end

.from_href(href) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/datmachine.rb', line 49

def from_href(href)
  split_uri = split_the_href(href)
  split_uri.reverse!.each do |resource|
    cls = Datmachine.hypermedia_registry[resource]
    return cls unless cls.nil?
  end
end

.from_hypermedia_registry(resource_name) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/datmachine.rb', line 41

def from_hypermedia_registry(resource_name)
  cls = Datmachine.hypermedia_registry[resource_name]
  if cls.nil?
    raise 'OH SHIT'
  end
  cls
end

.get(*args, &block) ⇒ Object



63
64
65
# File 'lib/datmachine.rb', line 63

def get(*args, &block)
  self.client.get *args
end

.is_collection(href) ⇒ Object



57
58
59
60
61
# File 'lib/datmachine.rb', line 57

def is_collection(href)
  split_uri = split_the_href(href)
  split_uri.last.to_i == 0

end

.is_configured_with_api_key?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/datmachine.rb', line 33

def is_configured_with_api_key?
  !@client.api_key.nil?
end

.post(*args, &block) ⇒ Object



67
68
69
# File 'lib/datmachine.rb', line 67

def post(*args, &block)
  self.client.post *args
end

.put(*args, &block) ⇒ Object



71
72
73
# File 'lib/datmachine.rb', line 71

def put(*args, &block)
  self.client.put *args
end

.split_the_href(href) ⇒ Object



37
38
39
# File 'lib/datmachine.rb', line 37

def split_the_href(href)
  URI.parse(href).path.sub(/\/$/, '').split('/')
end

.unstore(*args, &block) ⇒ Object Also known as: delete



75
76
77
# File 'lib/datmachine.rb', line 75

def unstore(*args, &block)
  self.client.unstore *args
end