atlas-utils 0.0.1 → 0.0.5

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: 714728b6ef1099397525bb40d6172995444cbc1a3e49de7c84ba191ed8940c87
4
- data.tar.gz: 5eefc6e33e5aabeb394f73d49d8791e9939d51229525d2fd4de42c9e7ae61667
3
+ metadata.gz: e96aa8d3dff545f16b4940a087e7c264f682be82b4ac9a86a106fa7fff779e1e
4
+ data.tar.gz: 32115b02c0c2e4b9ac6e90170c4c8345874d64b8b53c1abf5cf74d91d93a7fe6
5
5
  SHA512:
6
- metadata.gz: 2e4fa91681f550840bbe37c782d7ed2de5b08b1373614dc5005c332828eca7beafdb7ed951aef450183912884643bbac55dd456e8f251908ff700bad6b450094
7
- data.tar.gz: 85b6d4815ed2f52591ec72cb4c6df4004f7b32df8e96699fe7d5d2fc13b7a1f4a52a53d073194118a88c4c1ea7f135f02ecbe356f5d2133477233f82f2feeb41
6
+ metadata.gz: 6087f43fb2b3f7c1367234849e2559396bcc1e072199183787faeb06cc81c21b03920cdd3cf63cacc74fd8ace27d80052ca99c9c9ff460eef400d12a6c692693
7
+ data.tar.gz: d29a04182a02476c5e4aa66f2c964de8054d893673ace5ddfb11690b5196df2aa46d6d7b805a8859a4049d43ecf2ac76cbcf6b604ba1292021436819055d55fd
@@ -8,8 +8,8 @@ module AtlasUtils
8
8
  @platform = config_params[:platform]
9
9
  @language = config_params[:language]
10
10
  @territory = config_params[:territory]
11
- @root_menu_url = configurator['environments'][@env][@territory]['base_seamless_url']
12
- @root_pcms_url = configurator['environments'][@env][@territory]['base_pcms_url']
11
+ @base_pcms_url = configurator['hosts'][@env]
12
+ @root_menu_url = @base_pcms_url + configurator['seamlessUrl']
13
13
 
14
14
  puts "Env: #{@env} Device: #{@device} Platform: #{@platform } Lang: #{@language} Territory: #{@territory}"
15
15
  end
@@ -27,112 +27,106 @@ module AtlasUtils
27
27
  RestHelper.get_from_api(@root_menu_url)
28
28
  end
29
29
 
30
- def menu_json
30
+ def root_menu_json
31
31
  api_response(@root_menu_url)
32
32
  end
33
33
 
34
- def sub_menu_json
35
- menu_json['relationships']['items']['data']
36
- end
37
-
38
- def sub_menu_titles
39
- sub_menu_json.map { |menu| menu['attributes']['title'] }
34
+ def menu_json
35
+ root_menu_json['relationships']['items']['data']
40
36
  end
41
37
 
42
- def api_response(url)
43
- RestHelper.get_from_api(url, json_headers)
38
+ def menu_titles
39
+ menu_json.map { |menu| menu['attributes']['title'] }
44
40
  end
45
41
 
46
- def sub_menu_item_json(menu)
47
- sub_menu_item_json = nil
48
- sub_menu_json.each do |collection|
49
- sub_menu_item_json = collection['relationships']['items']['data'] if collection['attributes']['alias'] == menu
50
- end
51
- sub_menu_item_json
42
+ def sub_menu_titles(menu)
43
+ menu_item_json(menu)['relationships']['items']['data'].map { |menu| menu['attributes']['title'] }
52
44
  end
53
45
 
54
- def catalogue_group_json(menu, menu_item)
55
- catalogue_group_json = nil
56
- sub_menu_item_json = sub_menu_item_json(menu)
57
- sub_menu_item_json.each do |sub_collection|
58
- if sub_collection['attributes']['alias'].eql? menu_item
59
- catalogue_group_json = sub_collection['relationships']['items']['data']
46
+ def menu_item_json(menu)
47
+ menu_item_json = nil
48
+ menu_json.each do |collection|
49
+ if collection['attributes']['title'].casecmp(menu)==0
50
+ if collection['relationships'] && collection['relationships']['items']
51
+ menu_item_json = collection
52
+ end
60
53
  end
61
- end
62
- catalogue_group_json
63
- end
64
54
 
65
- def sub_menu_url(menu, menu_item)
66
- return_url = nil
67
- catalogue_group_json = catalogue_group_json(menu, menu_item)
68
- catalogue_group_json.each do |catalogue_group_collection|
69
- catalogue_collection_json = api_response(@root_pcms_url
70
- .+ catalogue_group_collection['links']['self']
71
- .+ '?represent=(items)')
72
- return_url = catalogue_collection_json['relationships']['items']['data'][0]['links']['self']
73
- return_url += '?represent=(items[take=50,skip=0])'
74
55
  end
75
- return_url
56
+ menu_item_json
76
57
  end
77
58
 
78
- # possible to set asset as an integer (position) or a string (title) to get the attributes of a specific asset
79
- # default is 1 (first asset in the view)
80
- def movie_attributes(menu, sub_menu, asset = 1)
81
- asset = get_asset_api_position(menu, sub_menu, asset) if asset.is_a? String
82
- movies_details_from_api = api_response(@root_pcms_url + sub_menu_url(menu, sub_menu))
83
- movies_details_from_api['relationships']['items']['data'][asset - 1]['attributes']
59
+ def catalogue_collections(link)
60
+ sub_catalogue_titles_collection = []
61
+ sub_collection_json = api_response(@base_pcms_url
62
+ .+ link + '?represent=(items)')
63
+ if sub_collection_json['type']=='CATALOGUE/GROUP'
64
+ # puts "Collection:==> #{sub_collection_json['attributes']['title']} is a GROUP"
65
+ sub_collection_json['relationships']['items']['data'].each do |sub_group|
66
+ sub_catalogue_titles_collection.concat(catalogue_collections(sub_group['links']['self']))
67
+ end
68
+ else
69
+ if sub_collection_json['relationships'] && sub_collection_json['relationships']['items']
70
+ sub_catalogue_titles_collection.concat(sub_collection_json['relationships']['items']['data'])
71
+ end
72
+ end
73
+ return sub_catalogue_titles_collection
84
74
  end
85
75
 
86
- def movie_items_data(menu, sub_menu, movie_number = 1)
87
- movies_details_from_api = api_response(@root_pcms_url + sub_menu_url(menu, sub_menu))
88
- movie_url = movies_details_from_api['relationships']['items']['data'][movie_number - 1]['links']['self']
89
- movie_data = api_response(@root_pcms_url + movie_url + '?represent=(items,recs)')
90
- movie_data
76
+ def catalogue_group_json(menu)
77
+ menu_item_json = menu_item_json(menu)
78
+ puts "Getting all asset details for #{menu} menu...."
79
+ catalogue_collections(menu_item_json['links']['self'])
91
80
  end
92
81
 
93
- def get_asset_api_position(menu, sub_menu, title)
94
- all_titles_from_api = api_response(@root_pcms_url
95
- .+ sub_menu_url(menu, sub_menu))['relationships']['items']['data']
96
- all_titles_from_api.map! { |v| v['attributes']['title'] }
97
- all_titles_from_api.index(title) + 1
82
+ def catalogue_collection(menu)
83
+ menu_titles.each do |menu_title|
84
+ if menu_title.casecmp(menu) == 0
85
+ unless instance_variable_get("@catalogue_#{menu}_collection")
86
+ instance_variable_set("@catalogue_#{menu}_collection",catalogue_group_json(menu))
87
+ end
88
+ return instance_variable_get("@catalogue_#{menu}_collection")
89
+ end
90
+ end
98
91
  end
99
92
 
100
- def get_menu_title(menu_alias)
101
- menu_title = nil
102
- sub_menu_json.each do |collection|
103
- menu_title = collection['attributes']['title'] if collection['attributes']['alias'] == menu_alias
104
- end
105
- menu_title
93
+ def api_response(url)
94
+ RestHelper.get_from_api(url, json_headers)
106
95
  end
107
96
 
108
- def get_menu_item_title(menu_alias, menu_item_alias)
109
- menu_item_title = nil
110
- sub_menu_item_json = sub_menu_item_json(menu_alias)
111
- sub_menu_item_json.each do |sub_collection|
112
- if sub_collection['attributes']['alias'].eql? menu_item_alias
113
- menu_item_title = sub_collection['attributes']['title']
114
- end
97
+ def get_asset_details_using_title(menu, asset_title)
98
+ assets_in_catalogue = catalogue_collection(menu)
99
+ # puts assets_in_catalogue
100
+ asset = assets_in_catalogue.find {|e| e['attributes']['title'].casecmp(asset_title)==0}
101
+ if asset
102
+ return get_asset_details_from_nodeid(asset['id'])
103
+ else
104
+ return "No asset matched title #{asset_title}"
115
105
  end
116
- menu_item_title
117
106
  end
118
107
 
119
- def get_asset_details(node_id)
120
- node_url = @configurator['environments'][@env][@territory]['node_url']
121
- asset_details_from_api = api_response(node_url+node_id)
108
+ def get_asset_details_from_nodeid(node_id)
109
+ node_url = @configurator['node_url']
110
+ asset_details_from_api = api_response(@base_pcms_url+ node_url + node_id)
122
111
  asset_details_from_api
123
112
  end
124
113
  end
125
114
 
126
- def self.test_settings(config)
127
- @test_settings ||= YAML.load_file(AtlasUtils.get_file_path(config))
115
+ def self.test_settings(config_type, config)
116
+ if config_type == "YML"
117
+ puts config
118
+ return (@test_settings ||= YAML.load_file(AtlasUtils.get_file_path(config)))
119
+ else
120
+ return (@test_settings ||= JSON.parse(File.read(AtlasUtils.get_file_path(config))))
121
+ end
128
122
  end
129
123
 
130
124
  def self.get_file_path(filename)
131
125
  File.join(Dir.pwd, filename)
132
126
  end
133
127
 
134
- def self.menu_api_helper(config, config_params)
135
- configurator = AtlasUtils.test_settings(config)
128
+ def self.menu_api_helper(config_type, config, config_params)
129
+ configurator = AtlasUtils.test_settings(config_type, config)
136
130
  @menu_api_helper ||= AtlasUtils::Menu.new(configurator, config_params)
137
131
  end
138
132
  end
@@ -10,7 +10,6 @@ class RestHelper
10
10
  begin
11
11
  tries ||= 3
12
12
  api_response = RestClient.get(url, headers) { |response, _request| response }
13
- # expect(api_response.code).to eq(200)
14
13
  if api_response.code != 200
15
14
  puts "ERROR in get_from_api: response code #{api_response.code}"
16
15
  end
@@ -29,63 +28,4 @@ class RestHelper
29
28
  end
30
29
  respo
31
30
  end
32
-
33
- def self.get_from_api_search(url)
34
- api_response = RestClient.get(url, json_headers_search) { |response, _request| response }
35
- # expect(api_response.code).to eq(200)
36
- if api_response.code != 200
37
- puts "ERROR in get_from_api_search: response code #{api_response.code}"
38
- end
39
- JSON.parse(api_response)
40
- end
41
-
42
- def self.json_headers_search
43
- headers = { 'x-skyott-proposition' => 'NOWTV',
44
- 'x-skyott-language' => 'en',
45
- 'x-skyott-territory' => 'GB' }
46
-
47
- # headers['sky-resiliency'] = ENV['RESILIENCY_HEADER'] if ENV['RESILIENCY_HEADER']
48
- headers
49
- end
50
-
51
- # captcha
52
- def self.clear_captcha_if_presented(sign_in_url, username, password)
53
- sign_in_payload = 'userIdentifier='"#{username}"'&password='"#{password}"
54
- api_response = RestClient.post(sign_in_url, sign_in_payload, rango_headers) { |response, _request| response }
55
- puts "API Response: \n #{api_response}"
56
- clear_captcha(JSON.parse(api_response)) unless api_response.code.eql?(201)
57
- end
58
-
59
- def self.clear_captcha(api_response)
60
- captcha_url = 'https://uiapi.id.stage.nowtv.com/signin/securitycheck/service/international'
61
- puts "Captcha URL: #{captcha_url}"
62
- captcha_session_id = api_response['actions'][0]['fields'][2]['value']
63
- captcha_id, captcha_value = get_captcha(captcha_url)
64
- puts "captchaid, value : #{captcha_id}, #{captcha_value}"
65
- send_captcha(captcha_url, captcha_id, captcha_value, captcha_session_id)
66
- end
67
-
68
- def self.send_captcha(captcha_url, captcha_id, captcha_value, captcha_session_id)
69
- payload = 'captcha='"#{captcha_value}"'&captchaId='"#{captcha_id}"'&captchaSessionId='"#{captcha_session_id}"
70
- puts "send captcha payload #{payload}"
71
- api_response = RestClient.post(captcha_url, payload, rango_headers) { |response, _request| response }
72
- puts "response code : #{api_response.code}"
73
- puts "response : #{api_response}"
74
- end
75
-
76
- def self.get_captcha(captcha_url)
77
- api_response = RestClient.post(captcha_url, '', rango_headers) { |response, _request| response }
78
- captcha_id = JSON.parse(api_response)['properties']['captchaId']
79
- captcha_value = api_response.cookies['captchaValue']
80
- [captcha_id, captcha_value]
81
- end
82
-
83
- def self.rango_headers
84
- {
85
- 'content-type' => 'application/x-www-form-urlencoded',
86
- 'x-skyott-provider' => 'NOWTV',
87
- 'x-skyott-territory' => 'GB'
88
- }
89
- end
90
- # end of captcha
91
31
  end
@@ -1,7 +1,7 @@
1
1
  module AtlasUtils
2
2
  class WhoIs
3
3
  def self.awesome?
4
- puts "PRIYA: WORLD IS ALWAYS AWESOME!!"
4
+ puts "PRIYA: EVERYTHING IS AWESOME & EVERYTHING IS SO COOL!!"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: atlas-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sripriya Raghunatha
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-02 00:00:00.000000000 Z
11
+ date: 2018-08-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: sripriya.raghunatha@sky.uk