Class: Moip::Assinaturas::Subscription

Inherits:
Object
  • Object
show all
Defined in:
lib/moip-assinaturas/subscription.rb

Class Method Summary collapse

Class Method Details

.activate(code, opts = {}) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/moip-assinaturas/subscription.rb', line 105

def activate(code, opts={})
  response = Moip::Assinaturas::Client.activate_subscription(code, opts)
  hash     = JSON.load(response.body)
  hash     = hash ? hash.with_indifferent_access : {}

  case response.code
  when 200
    return { success: true }
  when 400
    return {
      success: false,
      message: hash[:message],
      errors:  hash[:errors]
    }
  else
    raise(WebServerResponseError, "Ocorreu um erro no retorno do webservice")
  end
end

.cancel(code, opts = {}) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/moip-assinaturas/subscription.rb', line 124

def cancel(code, opts={})
  response = Moip::Assinaturas::Client.cancel_subscription(code, opts)
  hash     = JSON.load(response.body)
  hash     = hash ? hash.with_indifferent_access : {}

  case response.code
  when 200
    return { success: true }
  when 400
    return {
      success: false,
      message: hash[:message],
      errors:  hash[:errors]
    }
  else
    raise(WebServerResponseError, "Ocorreu um erro no retorno do webservice")
  end
end

.create(subscription, new_customer = false, opts = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/moip-assinaturas/subscription.rb', line 6

def create(subscription, new_customer = false, opts={})
  response = Moip::Assinaturas::Client.create_subscription(subscription, new_customer, opts)
  hash     = JSON.load(response.body).with_indifferent_access

  case response.code
  when 201
    return {
      success: true,
      subscription: hash
    }
  when 400
    return {
      success: false,
      message: hash[:message],
      errors:  hash[:errors]
    }
  else
    raise(WebServerResponseError, "Ocorreu um erro no retorno do webservice")
  end
end

.details(code, opts = {}) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/moip-assinaturas/subscription.rb', line 65

def details(code, opts={})
  response = Moip::Assinaturas::Client.details_subscription(code, opts)
  hash     = JSON.load(response.body)
  hash     = hash.with_indifferent_access if hash

  case response.code
  when 200
    return {
      success: true,
      subscription: hash
    }
  when 404
    return {
      success: false,
      message: 'not found'
    }
  else
    raise(WebServerResponseError, "Ocorreu um erro no retorno do webservice")
  end
end

.list(opts = {}) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/moip-assinaturas/subscription.rb', line 49

def list(opts={})
  response = Moip::Assinaturas::Client.list_subscriptions(opts)
  hash     = JSON.load(response.body).with_indifferent_access

  case response.code
  when 200
    return {
      success: true,
      subscriptions: hash[:subscriptions]
    }
  else
    raise(WebServerResponseError, "Ocorreu um erro no retorno do webservice")
  end

end

.suspend(code, opts = {}) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/moip-assinaturas/subscription.rb', line 86

def suspend(code, opts={})
  response = Moip::Assinaturas::Client.suspend_subscription(code, opts)
  hash     = JSON.load(response.body)
  hash     = hash ? hash.with_indifferent_access : {}

  case response.code
  when 200
    return { success: true }
  when 400
    return {
      success: false,
      message: hash[:message],
      errors:  hash[:errors]
    }
  else
    raise(WebServerResponseError, "Ocorreu um erro no retorno do webservice")
  end
end

.update(subscription_code, subscription_changes, opts = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/moip-assinaturas/subscription.rb', line 27

def update(subscription_code, subscription_changes, opts = {})
  response = Moip::Assinaturas::Client.update_subscription(subscription_code, subscription_changes, opts)
  hash     = JSON.load(response.body)
  hash     = hash ? hash.with_indifferent_access : {}

  case response.code
  when 200
    return {
      success: true
    }
  when 400
    return {
      success: false,
      message: hash[:message],
      errors:  hash[:errors]
    }
  else
    raise(WebServerResponseError, "Ocorreu um erro no retorno do webservice")
  end
end