Class: Billy::Service

Inherits:
BaseModel show all
Defined in:
lib/billy/service.rb

Instance Attribute Summary

Attributes inherited from BaseModel

#attributes

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#initialize, #method_missing

Constructor Details

This class inherits a constructor from Billy::BaseModel

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Billy::BaseModel

Class Method Details

.create(atech_identity, service) ⇒ Object



77
78
79
80
# File 'lib/billy/service.rb', line 77

def self.create(atech_identity, service)
  attributes = Billy::Request.request('services/create', :service => service, :atech_identity_key => atech_identity)
  attributes.is_a?(Hash) ? self.new(attributes) : nil
end

.find(field, data) ⇒ Object



68
69
70
71
# File 'lib/billy/service.rb', line 68

def self.find(field, data)
  attributes = Billy::Request.request('services/info', :field => field, :data => data)
  attributes.is_a?(Hash) ? self.new(attributes) : nil
end

.find_for_identity(ati_key) ⇒ Object



73
74
75
# File 'lib/billy/service.rb', line 73

def self.find_for_identity(ati_key)
  Billy::Request.request('services/list_for_identity', :atech_identity_key => ati_key).map { |p| self.new(p) }
end

.validate_label(label) ⇒ Object



82
83
84
85
86
87
88
89
# File 'lib/billy/service.rb', line 82

def self.validate_label(label)
  result = Billy::Request.request('services/validate_label', :label => label)
  if result.is_a?(Hash)
    result['status'] == 'error' ? result['errors'] : true
  else
    false
  end
end

Instance Method Details

#address?Boolean

Returns:

  • (Boolean)


63
64
65
66
# File 'lib/billy/service.rb', line 63

def address?
  return false if self.address.first.nil? || self.address.last.nil?
  return true
end

#change_label(new_label) ⇒ Object

Change the label associated with a service



41
42
43
44
45
46
47
48
49
# File 'lib/billy/service.rb', line 41

def change_label(new_label)
  request = Billy::Request.request('services/change_label', :id => @attributes['id'], :label => new_label)
  if request
    @attributes = request
    return true
  else
    return false
  end
end

#change_user(atech_identity_key) ⇒ Object

Change the user associated with this service to the given aTech identity key



30
31
32
33
34
35
36
37
38
# File 'lib/billy/service.rb', line 30

def change_user(atech_identity_key)
  request = Billy::Request.request('services/change_user', :id => @attributes['id'], :atech_identity_key => atech_identity_key)
  if request
    @attributes = request
    return true
  else
    return false
  end
end

#create_invoice(options = {}) ⇒ Object

Create a new invoice for the service and return the new invoice object



52
53
54
55
# File 'lib/billy/service.rb', line 52

def create_invoice(options = {})
  attributes = Billy::Request.request('invoices/create', :service => @attributes['id'], :invoice => options)
  attributes.is_a?(Hash) ? Billy::Invoice.new(attributes) : nil
end

#create_session(start_path = nil, return_url = nil, auto_return_after_payment = false) ⇒ Object

Create a new login session and return a URL which can be used to log the user into the billing application



17
18
19
20
# File 'lib/billy/service.rb', line 17

def create_session(start_path = nil, return_url = nil, auto_return_after_payment = false)
  session = Billy::Request.request('services/create_session', :id => @attributes['id'], :start_path => start_path, :return_url => return_url, :auto_return_after_payment => auto_return_after_payment)
  session ? [Billy.host, 'start', session['token']].join('/') : false
end

#create_signup_token(product, package) ⇒ Object

Create a new signup token for another application



23
24
25
26
27
# File 'lib/billy/service.rb', line 23

def (product, package)
  return false if product.nil? || package.nil?
  token = Billy::Request.request('services/create_signup_token', :id => @attributes['id'], :product => product, :package => package)
  token ? token['url'] : false
end

#invoice(number) ⇒ Object

Return the invoice for this service



58
59
60
61
# File 'lib/billy/service.rb', line 58

def invoice(number)
  attributes = Billy::Request.request('invoices/info', :invoice => number, :service => @attributes['id'])
  attributes.is_a?(Hash) ? Billy::Invoice.new(attributes) : nil
end

#listObject

Get a paginated list of all Billy services



5
6
7
# File 'lib/billy/service.rb', line 5

def list
  Billy::Request.request('services/list')
end

#update(properties) ⇒ Object

Update an existing service by passing new properties



10
11
12
13
# File 'lib/billy/service.rb', line 10

def update(properties)
  @attributes = Billy::Request.request('services/update', :service => @attributes['id'],:properties => properties)
  true
end