altadata 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ba3bd8d384a691b9367ca59cd75fc5f8c373dc92ac7b12b731272a932f3ef66e
4
- data.tar.gz: 366e45a3aeed84b93658f00090dc4d3cf128e1323d2c888a1d38cc226cf5ae12
3
+ metadata.gz: 4038d966cc01b808509c51bbd99c11efb44a6a88656df0b6638c35ac7697975a
4
+ data.tar.gz: 5dc00fd520c51880c7501bd764c138919d4dc7289999536381353ccc8c48cc0c
5
5
  SHA512:
6
- metadata.gz: 4b78fa04c30a8879b9e404389741266bb9527379b7b140a5e61a5f329bb3c0b070503ea7b57595c7ffe39e102b06410b4fd1814d251c39d7f02182833029d6ed
7
- data.tar.gz: 515c57033050a32ce2954def0cd150b3be52e2a5c0a547dd8e7099fff5b587593b52a321d60b8390bc730ad4a53035fc73e2c7d10d93c97bca5aacfb48dedc4d
6
+ metadata.gz: 55efddb449da59699cc841ffd3b90a443fde140e1473e58a2d42c91b0d5acc69685b55ba4e91f86daf8dffc3b14b261de612e8a2aaced87edb95fdf61a70c2ad
7
+ data.tar.gz: 4c29575a0bf0d2bb30f7a6e10c6dd5bfab4b1effea120248f318a1192267d19a59f4b2d546b06fbf37d6021f72a1e87729be692b7dd63ab0a80e64583b8214aa
@@ -15,11 +15,37 @@ module Altadata
15
15
  @subscription_api_url = "https://www.altadata.io/subscription/api/subscriptions?api_key=#{@api_key}"
16
16
  end
17
17
 
18
+ ##
19
+ # Converts subscription api response to unnested version
20
+ def fix_subscription_response(response_json)
21
+ data = []
22
+
23
+ response_json.each do |product|
24
+ product_item = product
25
+ product_item['createdAt'] = product_item['createdAt'].gsub('T', ' ').split('+')[0]
26
+ product_item['validUntil'] = product_item['validUntil'].gsub('T', ' ').split('+')[0]
27
+ product_item['title'] = product_item['offer']['title']
28
+ product_item['code'] = product_item['offer']['code']
29
+ product_item['price'] = product_item['plan']['price']
30
+ product_item['plan_name'] = product_item['plan']['title']
31
+ product_item['period'] = product_item['plan']['period']
32
+
33
+ product_item.delete('id')
34
+ product_item.delete('offer')
35
+ product_item.delete('plan')
36
+
37
+ data << product_item
38
+ end
39
+
40
+ data
41
+ end
42
+
18
43
  ##
19
44
  # Retrieves customer's subscription info
20
45
  def list_subscription
21
46
  response = Faraday.get(@subscription_api_url)
22
- JSON.parse(response.body)
47
+ response_json = JSON.parse(response.body)
48
+ fix_subscription_response(response_json)
23
49
  end
24
50
 
25
51
  ##
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Altadata
4
- VERSION = '0.0.1'
4
+ VERSION = '0.0.2'
5
5
  end
@@ -17,7 +17,7 @@ RSpec.describe Altadata do
17
17
  product_code_arr = []
18
18
 
19
19
  subscription_info.each do |info|
20
- product_code_arr << info['offer']['code']
20
+ product_code_arr << info['code']
21
21
  end
22
22
 
23
23
  product_code_list = %w[CO_10_JHUCS_04 CO_08_UNXXX_04
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: altadata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ALTADATA