atlas-utils 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/atlas_utils.rb +115 -0
- data/lib/atlas_utils/rest_helper.rb +107 -0
- data/lib/atlas_utils/test.rb +7 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bae9a183af4b390a18da60041426509857f69542f049544386c5b43aa2688569
|
4
|
+
data.tar.gz: 94c0efd9dc8c238d89fa52e8a82c17017072306f26d9ff9513378237dc1fd709
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f274726b8d638091376725d976434b467744cf964eba9e4ea9706fb477c3dffbe38245d0181d7d777813d104b0bbaa06d863dfe11b4656283ecf767e705a11a0
|
7
|
+
data.tar.gz: b61556b17264354e265c8991418eb74fbe46cb528bf54b9ece003aeff38ca666300abdd779afe0143638708d25ee54c6dffa07213e2baf021c73d1d175d3f6fb
|
data/lib/atlas_utils.rb
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
module AtlasUtils
|
2
|
+
class Menu
|
3
|
+
def initialize(base_menu_url, base_pcms_url)
|
4
|
+
puts base_menu_url
|
5
|
+
puts base_pcms_url
|
6
|
+
puts "******"
|
7
|
+
@root_menu_url = base_menu_url
|
8
|
+
@root_pcms_url = base_pcms_url
|
9
|
+
end
|
10
|
+
|
11
|
+
def root_menu_collection
|
12
|
+
RestHelper.get_from_api(@root_menu_url)
|
13
|
+
end
|
14
|
+
|
15
|
+
def menu_json
|
16
|
+
api_response(@root_menu_url)
|
17
|
+
end
|
18
|
+
|
19
|
+
def sub_menu_json
|
20
|
+
menu_json['relationships']['items']['data'][1]['relationships']['items']['data']
|
21
|
+
end
|
22
|
+
|
23
|
+
def sub_menu_titles
|
24
|
+
sub_menu_json.map { |menu| menu['attributes']['title'] }
|
25
|
+
end
|
26
|
+
|
27
|
+
def api_response(url)
|
28
|
+
RestHelper.get_from_api(url)
|
29
|
+
end
|
30
|
+
|
31
|
+
def sub_menu_item_json(menu)
|
32
|
+
sub_menu_item_json = nil
|
33
|
+
sub_menu_json.each do |collection|
|
34
|
+
sub_menu_item_json = collection['relationships']['items']['data'] if collection['attributes']['alias'] == menu
|
35
|
+
end
|
36
|
+
sub_menu_item_json
|
37
|
+
end
|
38
|
+
|
39
|
+
def catalogue_group_json(menu, menu_item)
|
40
|
+
catalogue_group_json = nil
|
41
|
+
sub_menu_item_json = sub_menu_item_json(menu)
|
42
|
+
sub_menu_item_json.each do |sub_collection|
|
43
|
+
if sub_collection['attributes']['alias'].eql? menu_item
|
44
|
+
catalogue_group_json = sub_collection['relationships']['items']['data']
|
45
|
+
end
|
46
|
+
end
|
47
|
+
catalogue_group_json
|
48
|
+
end
|
49
|
+
|
50
|
+
def sub_menu_url(menu, menu_item)
|
51
|
+
return_url = nil
|
52
|
+
catalogue_group_json = catalogue_group_json(menu, menu_item)
|
53
|
+
catalogue_group_json.each do |catalogue_group_collection|
|
54
|
+
catalogue_collection_json = api_response(@root_pcms_url
|
55
|
+
.+ catalogue_group_collection['links']['self']
|
56
|
+
.+ '?represent=(items)')
|
57
|
+
return_url = catalogue_collection_json['relationships']['items']['data'][0]['links']['self']
|
58
|
+
return_url += '?represent=(items[take=50,skip=0])'
|
59
|
+
end
|
60
|
+
return_url
|
61
|
+
end
|
62
|
+
|
63
|
+
# possible to set asset as an integer (position) or a string (title) to get the attributes of a specific asset
|
64
|
+
# default is 1 (first asset in the view)
|
65
|
+
def movie_attributes(menu, sub_menu, asset = 1)
|
66
|
+
asset = get_asset_api_position(menu, sub_menu, asset) if asset.is_a? String
|
67
|
+
movies_details_from_api = api_response(@root_pcms_url + sub_menu_url(menu, sub_menu))
|
68
|
+
movies_details_from_api['relationships']['items']['data'][asset - 1]['attributes']
|
69
|
+
end
|
70
|
+
|
71
|
+
def movie_items_data(menu, sub_menu, movie_number = 1)
|
72
|
+
movies_details_from_api = api_response(@root_pcms_url + sub_menu_url(menu, sub_menu))
|
73
|
+
movie_url = movies_details_from_api['relationships']['items']['data'][movie_number - 1]['links']['self']
|
74
|
+
movie_data = api_response(@root_pcms_url + movie_url + '?represent=(items,recs)')
|
75
|
+
movie_data
|
76
|
+
end
|
77
|
+
|
78
|
+
def get_asset_api_position(menu, sub_menu, title)
|
79
|
+
all_titles_from_api = api_response(@root_pcms_url
|
80
|
+
.+ sub_menu_url(menu, sub_menu))['relationships']['items']['data']
|
81
|
+
all_titles_from_api.map! { |v| v['attributes']['title'] }
|
82
|
+
all_titles_from_api.index(title) + 1
|
83
|
+
end
|
84
|
+
|
85
|
+
def get_menu_title(menu_alias)
|
86
|
+
menu_title = nil
|
87
|
+
sub_menu_json.each do |collection|
|
88
|
+
menu_title = collection['attributes']['title'] if collection['attributes']['alias'] == menu_alias
|
89
|
+
end
|
90
|
+
menu_title
|
91
|
+
end
|
92
|
+
|
93
|
+
def get_menu_item_title(menu_alias, menu_item_alias)
|
94
|
+
menu_item_title = nil
|
95
|
+
sub_menu_item_json = sub_menu_item_json(menu_alias)
|
96
|
+
sub_menu_item_json.each do |sub_collection|
|
97
|
+
if sub_collection['attributes']['alias'].eql? menu_item_alias
|
98
|
+
menu_item_title = sub_collection['attributes']['title']
|
99
|
+
end
|
100
|
+
end
|
101
|
+
menu_item_title
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
|
106
|
+
def self.menu_api_helper
|
107
|
+
base_menu_url = "https://ie.api.atom.nowtv.com/adapter-atlas/v3/query/node/group_id/Home?represent=(items[where=(type=CATALOGUE/COLLECTION),take=1](items[where=(type=ASSET/PROGRAMME%7CCATALOGUE/SERIES%7CASSET/LINEAR%7CASSET/EPISODE%7CCATALOGUE/SEASON)]),items[where=(type=CATALOGUE/LINK)],items[where=(type=CATALOGUE/GROUP)](items[where=(type=CATALOGUE/COLLECTION),take=1](items[take=10]))))"
|
108
|
+
base_pcms_url = "http://ie.api.atom.nowtv.com"
|
109
|
+
puts "In MAH"
|
110
|
+
@menu_api_helper ||= AtlasUtils::Menu.new(base_menu_url, base_pcms_url)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
require 'atlas_utils/rest_helper.rb'
|
115
|
+
require 'atlas_utils/test'
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'rest-client'
|
3
|
+
|
4
|
+
class RestHelper
|
5
|
+
def self.get_from_api(url, additional_headers = {})
|
6
|
+
headers = json_headers
|
7
|
+
headers.merge!(additional_headers)
|
8
|
+
|
9
|
+
puts "URL: #{url}"
|
10
|
+
puts "HEADERS: #{headers}"
|
11
|
+
puts "!!!!!!!!!!!!!!!!!!!!!!"
|
12
|
+
# $LOG.debug("URL: #{url}")
|
13
|
+
# $LOG.debug("HEADERS: #{headers}")
|
14
|
+
|
15
|
+
begin
|
16
|
+
tries ||= 3
|
17
|
+
api_response = RestClient.get(url, headers) { |response, _request| response }
|
18
|
+
puts "RESPONSE CODE: #{api_response.code}"
|
19
|
+
api_response.code.should be == 200
|
20
|
+
respo = JSON.parse(api_response)
|
21
|
+
|
22
|
+
pcms_pattern = %r{\/adapter-atlas\/v3\/query\/node\/(.*)}
|
23
|
+
if url.match(pcms_pattern)
|
24
|
+
puts "NODE ID FROM RESPONSE: #{respo['id']}"
|
25
|
+
expect(respo['id']).to eq(url.match(pcms_pattern)[1].split('?').first)
|
26
|
+
end
|
27
|
+
rescue
|
28
|
+
puts'RESCUE in get_from_api'
|
29
|
+
if (tries -= 1) > 0
|
30
|
+
puts'RETRY REQUEST'
|
31
|
+
retry
|
32
|
+
else
|
33
|
+
puts'REQUEST FAILED 3 TIMES'
|
34
|
+
raise 'REST HELPER - get_from_api error'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
respo
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.json_headers
|
41
|
+
headers = { 'Content-Type' => 'application/json',
|
42
|
+
'x-skyott-proposition' => 'NOWTV',
|
43
|
+
'x-skyott-language' => 'en',
|
44
|
+
'x-skyott-territory' => 'GB',
|
45
|
+
'x-skyott-platform' => 'APPLETV',
|
46
|
+
'x-skyott-device' => 'IPSETTOPBOX' }
|
47
|
+
|
48
|
+
# headers['sky-resiliency'] = ENV['RESILIENCY_HEADER'] if ENV['RESILIENCY_HEADER']
|
49
|
+
headers
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.get_from_api_search(url)
|
53
|
+
api_response = RestClient.get(url, json_headers_search) { |response, _request| response }
|
54
|
+
api_response.code.should be == 200
|
55
|
+
JSON.parse(api_response)
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.json_headers_search
|
59
|
+
headers = { 'x-skyott-proposition' => 'NOWTV',
|
60
|
+
'x-skyott-language' => 'en',
|
61
|
+
'x-skyott-territory' => 'GB' }
|
62
|
+
|
63
|
+
# headers['sky-resiliency'] = ENV['RESILIENCY_HEADER'] if ENV['RESILIENCY_HEADER']
|
64
|
+
headers
|
65
|
+
end
|
66
|
+
|
67
|
+
# captcha
|
68
|
+
def self.clear_captcha_if_presented(sign_in_url, username, password)
|
69
|
+
sign_in_payload = 'userIdentifier='"#{username}"'&password='"#{password}"
|
70
|
+
api_response = RestClient.post(sign_in_url, sign_in_payload, rango_headers) { |response, _request| response }
|
71
|
+
puts "API Response: \n #{api_response}"
|
72
|
+
clear_captcha(JSON.parse(api_response)) unless api_response.code.eql?(201)
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.clear_captcha(api_response)
|
76
|
+
captcha_url = 'https://uiapi.id.stage.nowtv.com/signin/securitycheck/service/international'
|
77
|
+
puts "Captcha URL: #{captcha_url}"
|
78
|
+
captcha_session_id = api_response['actions'][0]['fields'][2]['value']
|
79
|
+
captcha_id, captcha_value = get_captcha(captcha_url)
|
80
|
+
puts "captchaid, value : #{captcha_id}, #{captcha_value}"
|
81
|
+
send_captcha(captcha_url, captcha_id, captcha_value, captcha_session_id)
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.send_captcha(captcha_url, captcha_id, captcha_value, captcha_session_id)
|
85
|
+
payload = 'captcha='"#{captcha_value}"'&captchaId='"#{captcha_id}"'&captchaSessionId='"#{captcha_session_id}"
|
86
|
+
puts "send captcha payload #{payload}"
|
87
|
+
api_response = RestClient.post(captcha_url, payload, rango_headers) { |response, _request| response }
|
88
|
+
puts "response code : #{api_response.code}"
|
89
|
+
puts "response : #{api_response}"
|
90
|
+
end
|
91
|
+
|
92
|
+
def self.get_captcha(captcha_url)
|
93
|
+
api_response = RestClient.post(captcha_url, '', rango_headers) { |response, _request| response }
|
94
|
+
captcha_id = JSON.parse(api_response)['properties']['captchaId']
|
95
|
+
captcha_value = api_response.cookies['captchaValue']
|
96
|
+
[captcha_id, captcha_value]
|
97
|
+
end
|
98
|
+
|
99
|
+
def self.rango_headers
|
100
|
+
{
|
101
|
+
'content-type' => 'application/x-www-form-urlencoded',
|
102
|
+
'x-skyott-provider' => 'NOWTV',
|
103
|
+
'x-skyott-territory' => 'GB'
|
104
|
+
}
|
105
|
+
end
|
106
|
+
# end of captcha
|
107
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: atlas-utils
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sripriya Raghunatha
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-08-02 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email: sripriya.raghunatha@sky.uk
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/atlas_utils.rb
|
20
|
+
- lib/atlas_utils/rest_helper.rb
|
21
|
+
- lib/atlas_utils/test.rb
|
22
|
+
homepage:
|
23
|
+
licenses: []
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 2.7.7
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: atlas-utils is the best
|
45
|
+
test_files: []
|