inews_client 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d98a52be678f8968600b1b243eeed727d78ccbd9
4
+ data.tar.gz: f836b379d18eeb345b692dbaa844c2203a66b471
5
+ SHA512:
6
+ metadata.gz: aa548f14ad1316d1ce6a4bddc25b6f30322bd628827d0ccf978684c7b3a4c2427479f151dc49b8be36be3da5c92759a84ea4c7a41771f7d18d33533f7a525a63
7
+ data.tar.gz: a9c4ae6411752f8e18ba9fda6bea4954e6c59590c229d8dbcb13d59612b80a8697422e2ff434b2ba1ed51c94627ce230811da30154bdaa835491620ade55fbb9
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # A sample Gemfile
2
+ source "https://rubygems.org"
3
+
4
+ # Specify your gem's dependencies in accounts-client.gemspec
5
+ gemspec
@@ -0,0 +1,61 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ inews_client (0.1.1)
5
+ libxml-ruby
6
+ savon (~> 2.3.0)
7
+ sax-machine
8
+ xpath
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ akami (1.2.2)
14
+ gyoku (>= 0.4.0)
15
+ nokogiri
16
+ builder (3.2.2)
17
+ coderay (1.1.0)
18
+ gyoku (1.1.1)
19
+ builder (>= 2.1.2)
20
+ httpi (2.1.0)
21
+ rack
22
+ rubyntlm (~> 0.3.2)
23
+ libxml-ruby (2.7.0)
24
+ method_source (0.8.2)
25
+ mime-types (1.25.1)
26
+ mini_portile (0.6.0)
27
+ nokogiri (1.6.2.1)
28
+ mini_portile (= 0.6.0)
29
+ nori (2.3.0)
30
+ pry (0.9.12.6)
31
+ coderay (~> 1.0)
32
+ method_source (~> 0.8)
33
+ slop (~> 3.4)
34
+ rack (1.5.2)
35
+ rake (10.3.2)
36
+ rubyntlm (0.3.4)
37
+ savon (2.3.3)
38
+ akami (~> 1.2.0)
39
+ builder (>= 2.1.2)
40
+ gyoku (~> 1.1.0)
41
+ httpi (~> 2.1.0)
42
+ nokogiri (>= 1.4.0)
43
+ nori (~> 2.3.0)
44
+ wasabi (~> 3.2.2)
45
+ sax-machine (0.2.1)
46
+ nokogiri (~> 1.6.0)
47
+ slop (3.5.0)
48
+ wasabi (3.2.3)
49
+ httpi (~> 2.0)
50
+ mime-types (< 2.0.0)
51
+ nokogiri (>= 1.4.0)
52
+ xpath (2.0.0)
53
+ nokogiri (~> 1.3)
54
+
55
+ PLATFORMS
56
+ ruby
57
+
58
+ DEPENDENCIES
59
+ inews_client!
60
+ pry
61
+ rake
@@ -0,0 +1,38 @@
1
+ # iNews-client
2
+
3
+ Ruby client for iNEWS Web Services API
4
+
5
+ The implementation here is mostly for watching a queue of stories, and checking
6
+ what the story status is.
7
+
8
+ This service works as a daemon that watches an iNEWS rundown while the show is
9
+ on air. You can get information about a story, and if it got fired already.
10
+
11
+ You can implement more actions of the iNEWS WSAPI easily with this client.
12
+ http://www.avid.com/static/resources/common/documents/iNEWS_Whitepaper.pdf
13
+
14
+
15
+ ## How To Install
16
+
17
+ ```
18
+ $ git clone https://github.com/gilbar11/iNewsClient.git
19
+ ```
20
+ ```
21
+ $ cd iNewsClient
22
+ ```
23
+ ```
24
+ $ bundle install
25
+ ```
26
+
27
+
28
+ ## Use cases
29
+
30
+ The service was developed under the assumption that for every rundown (TV
31
+ Show) there is a dedicated instance, which will be terminated at the end of
32
+ the show.
33
+
34
+ #### Launch
35
+
36
+ ```
37
+ $ bin/watcher "settings.yml"
38
+ ```
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+
5
+ project_root = File.join(File.dirname(__FILE__), '..')
6
+ external_root_project = File.join(File.dirname(__FILE__), '../../../..')
7
+ $LOAD_PATH << File.join(project_root, 'lib')
8
+
9
+ require 'inews_client'
10
+
11
+ exec = "watcher.rb"
12
+ exec = ARGF.argv.first if ARGF.argv
13
+
14
+ load File.join(external_root_project, exec)
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'inews_client/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "inews_client"
8
+ gem.version = InewsClient::VERSION
9
+ gem.authors = ["Gilad Barzilay"]
10
+ gem.email = ["gilbar11@gmail.com"]
11
+ gem.description = %q{ This service works as a daemon that watches an iNEWS rundown while the show is
12
+ on air. You can get information about a story, and if it got fired already }
13
+ gem.summary = %q{ Ruby client for iNEWS Web Services API }
14
+ gem.homepage = "https://github.com/gilbar11/iNews-client"
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.require_paths = ["lib"]
19
+ gem.add_dependency 'savon', '~> 2.3.0'
20
+ gem.add_dependency 'xpath'
21
+ gem.add_dependency 'sax-machine'
22
+ gem.add_dependency 'libxml-ruby'
23
+
24
+ gem.add_development_dependency 'rake'
25
+ gem.add_development_dependency 'pry'
26
+ end
@@ -0,0 +1,27 @@
1
+ require 'savon'
2
+ require 'inews_client/queue'
3
+ require 'inews_client/system'
4
+ require 'inews_client/story_entry'
5
+
6
+ module InewsClient
7
+ def self.watch_queue(&block)
8
+ fired_stories = []
9
+ interval = ENV['interval'].to_i
10
+ interval = 2 unless interval
11
+ InewsClient::System.session do |inews|
12
+ inews.queue.with_queue(ENV['current_queue']) do |queue|
13
+ loop do
14
+ sleep(ENV['interval'].to_i)
15
+ queue.stories.select {|s| s.fired? }.each do |story|
16
+ next if fired_stories.any? { |s| s.id == story.id }
17
+ fired_stories << story
18
+ block.call(story)
19
+ end
20
+
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+
@@ -0,0 +1,57 @@
1
+ module InewsClient
2
+ class Queue < Struct.new(:inews)
3
+ def client_options
4
+ {
5
+ wsdl: "#{ENV['wsdl']}/inewswebservice/services/inewsqueue?wsdl",
6
+ namespaces:{
7
+ "xmlns:types" => "http://avid.com/inewsqueue/types",
8
+ },
9
+ }
10
+ end
11
+
12
+ def get_stories
13
+ num_of_stories = ENV['stories_to_get'].to_i
14
+ num_of_stories = 50 unless num_of_stories
15
+ message = {
16
+ 'types:NumberOfStoriesToGet' => "#{num_of_stories}",
17
+ 'types:IsStoryBodyIncluded' => 'true',
18
+ 'types:Navigation' => 'SAME',
19
+ }
20
+ client.call(:get_stories, message: message, cookies: inews.auth_cookies)
21
+ end
22
+
23
+
24
+ def set_current_queue(queue_full_path)
25
+ message = {
26
+ 'types:QueueFullName' => queue_full_path,
27
+ }
28
+ client.call(:set_current_queue, message: message, cookies: inews.auth_cookies)
29
+ end
30
+
31
+ def with_queue(queue_full_path, &block)
32
+ set_current_queue(queue_full_path)
33
+ block.call(inews.queue)
34
+ end
35
+
36
+ def stories
37
+ get_stories.to_array(:get_stories_response, :stories).map { |story| StoryEntry.parse(story[:story_as_nsml]) }
38
+ end
39
+
40
+ def get_queue_records
41
+ message = {
42
+ 'types:NumberOfRecordsToGet' => '30',
43
+ 'types:Reset' => '0',
44
+ }
45
+ client.call(:get_queue_records, message: message, cookies: inews.auth_cookies)
46
+ end
47
+
48
+ def client
49
+ @client ||= Savon.client(client_options)
50
+ end
51
+
52
+ def ensure_connected!
53
+ inews.ensure_connected!
54
+ end
55
+ end
56
+ end
57
+
@@ -0,0 +1,22 @@
1
+ require 'sax-machine'
2
+
3
+ class StoryEntry
4
+ include SAXMachine
5
+ element :string, :as => :title, :with => {:id => "title"}
6
+ element :string, :as => :app_id, :with => {:id => "#{ENV['target_field_id']}" }
7
+ element :date, :as => :air_date, :with => {:id => "air-date"}
8
+ element :p, :as => :text
9
+
10
+ def fired?
11
+ self.air_date != "0" && self.air_date
12
+ end
13
+
14
+ def id
15
+ app_id.split('-').last if app_id
16
+ end
17
+
18
+ def field_content
19
+ self.app_id
20
+ end
21
+
22
+ end
@@ -0,0 +1,59 @@
1
+ module InewsClient
2
+ class System < Struct.new(:auth_cookies)
3
+ def queue
4
+ @queue ||= InewsClient::Queue.new(self)
5
+ end
6
+
7
+ def self.client_options
8
+ {
9
+ wsdl: "#{ENV['wsdl']}/inewswebservice/services/inewssystem?wsdl",
10
+ namespaces:{
11
+ "xmlns:types" => "http://avid.com/inewssystem/types",
12
+ },
13
+ }
14
+ end
15
+
16
+ def get_auth_cookies
17
+ auth_cookies
18
+ end
19
+
20
+ def self.client
21
+ Savon.client(client_options)
22
+ end
23
+
24
+ def self.connect()
25
+ message = {
26
+ 'types:Username' => ENV['username'],
27
+ 'types:Password' => ENV['password'],
28
+ 'types:Servername' => ENV['servername'],
29
+ }
30
+ client.call(:connect, message: message)
31
+ end
32
+
33
+ def is_connected(auth_cookies)
34
+ client.call(:is_connected, cookies: auth_cookies)
35
+ end
36
+
37
+ def ensure_connected!
38
+ unless is_connected(auth_cookies).body[:is_connected_response][:is_connected]
39
+ response = connect
40
+ self.auth_cookies = response.http.cookies
41
+ end
42
+ end
43
+
44
+ def self.session(&block)
45
+ response = connect
46
+ auth_cookies = response.http.cookies
47
+ if auth_cookies
48
+ client = InewsClient::System.new(auth_cookies)
49
+ block.call(client)
50
+ end
51
+ rescue Exception => e
52
+ puts e
53
+ ensure
54
+ if auth_cookies
55
+ self.client.call(:disconnect, cookies: auth_cookies)
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,3 @@
1
+ module InewsClient
2
+ VERSION = "0.1.2"
3
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: inews_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Gilad Barzilay
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: savon
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 2.3.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 2.3.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: xpath
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sax-machine
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: libxml-ruby
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: " This service works as a daemon that watches an iNEWS rundown while
98
+ the show is\non air. You can get information about a story, and if it got fired
99
+ already "
100
+ email:
101
+ - gilbar11@gmail.com
102
+ executables:
103
+ - watcher
104
+ extensions: []
105
+ extra_rdoc_files: []
106
+ files:
107
+ - Gemfile
108
+ - Gemfile.lock
109
+ - Readme.md
110
+ - bin/watcher
111
+ - inews_client.gemspec
112
+ - lib/inews_client.rb
113
+ - lib/inews_client/queue.rb
114
+ - lib/inews_client/story_entry.rb
115
+ - lib/inews_client/system.rb
116
+ - lib/inews_client/version.rb
117
+ homepage: https://github.com/gilbar11/iNews-client
118
+ licenses: []
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - '>='
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 2.0.3
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: Ruby client for iNEWS Web Services API
140
+ test_files: []