9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/internetbs/account_prices.rb', line 9
def fetch
@errors.clear
params = {'currency' => @currency, 'version' => @version}
optional_params = {'discountcode' => @discount_code}
params.merge!(optional_params) if @discount_code
response = Client.get('/account/pricelist/get', params)
code = response.code rescue ""
case code
when '200'
hash = JSON.parse(response.body)
@status = hash["status"]
@transaction_id = hash["transactid"]
if @status == 'SUCCESS'
case @version
when 1
hash['product'].each do |product|
@list << AccountPrice.new(
:currency => @currency,
:name => product['name'],
:price_1_year => product['price']
)
end
when 2
@level = hash['pricelevel']
@currency = hash['currency']
hash['product'].each do |product|
@list << AccountPrice.new(
:currency => @currency,
:name => product['type'],
:operation => product['operation'],
:price_1_year => product['period']['1'],
:price_2_years => product['period']['2'],
:price_3_years => product['period']['3'],
:price_4_years => product['period']['4'],
:price_5_years => product['period']['5'],
:price_6_years => product['period']['6'],
:price_7_years => product['period']['7'],
:price_8_years => product['period']['8'],
:price_9_years => product['period']['9'],
:price_10_years => product['period']['10']
)
end
end
else
set_errors(response)
return false
end
return true
else
set_errors(response)
return false
end
end
|