tvtid 0.2 → 0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ea4bedf76b78e369cfac3ad2e67444f5172c64b0
4
- data.tar.gz: 6c37d809faef50bd339f0678233744d9c554db91
3
+ metadata.gz: 36fbfc05fddc5323e3c0e56abf9ced86dc074474
4
+ data.tar.gz: 310a1705cfae16aa41e43b6fed1a8c7b4e9478f3
5
5
  SHA512:
6
- metadata.gz: 1bec9af98fa1f916b41a46946b35bef2a5b9feccef34d66a562aaf5975bd80c2911740d08ebe17575ac001839713695bfb44f5b94225846b5419835418ace21b
7
- data.tar.gz: '093bb630fb49e60928a4219c27515d65d2f935ae23c364bed377115383f4e42246db53af4bcd34f1a047fadd91869c8de0a3dcdebf0b4e45b36431c5cd5c5202'
6
+ metadata.gz: 4cff228acd985786abea49798e260d243a271754620e56e1a5e89e64b6570476558d1dba1de25efb9be505238c3c36758b5cf167d6b98837f380427ca7c07d24
7
+ data.tar.gz: 5605ff062067d737fa91e69142d16174c735955c3e4917541ea2d4714bc45dd3a10658066a5e2edc9f045306d74126c974a0b4777d7c5bf2cf58426d0bd75244
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2017, Mikkel Kroman <mk@uplink.io>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included
12
+ in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,2 +1,39 @@
1
- tvtid
2
- =====
1
+ # TVTid
2
+ This is a Ruby library for interfacing with the unofficial API on `tvtid.tv2.dk`.
3
+
4
+ [![Build Status](https://travis-ci.org/mkroman/tvtid.svg?branch=master)](https://travis-ci.org/mkroman/tvtid)
5
+ [![Dependency Status](https://gemnasium.com/mkroman/tvtid.svg)](https://gemnasium.com/mkroman/tvtid)
6
+
7
+ ## Example
8
+ ```ruby
9
+ require 'tvtid'
10
+
11
+ client = TVTid::Client.new
12
+ schedules = client.schedules_for_today
13
+ channel_length = client.channels.map(&:title).map(&:length).max
14
+
15
+ schedules.each do |schedule|
16
+ channel = schedule.channel
17
+ already_aired_programs, currently_running_program, upcoming_programs = schedule.current
18
+
19
+ if program = currently_running_program
20
+ print "#{channel.title.ljust channel_length} [#{program.start_time.strftime('%R')}] #{program.title} "
21
+
22
+ upcoming_programs[0...2].each do |program|
23
+ print "[#{program.start_time.strftime('%R')}] #{program.title} "
24
+ end
25
+
26
+ puts
27
+ end
28
+ end
29
+
30
+ # TV 2 [20:00] Fuld plade [21:15] Baby Surprise [23:05] Obsessed
31
+ # DR1 [20:00] X Factor [21:00] TV AVISEN [21:15] Vores vejr
32
+ # TV 2 Charlie [20:30] Fede Finn i modvind [21:25] Fede Finn i modvind [22:15] En sag for Frost
33
+ # DR2 [20:45] VM håndbold: Kroatien-Norge, direkte [21:20] VM håndbold: Studiet [21:35] VM håndbold: Kroatien-Norge, direkte
34
+ # TV3 [20:00] Dagens mand [21:00] American Pie 2 [23:10] The Joneses
35
+ # …
36
+ ```
37
+
38
+ ## License
39
+ `tvtid` is published under the MIT license which can be read in the `LICENSE` file.
@@ -20,16 +20,17 @@ module TVTid
20
20
  118, 153, 94, 12948, 145, 185, 157, 15, 71, 93, 15049,
21
21
  219, 37, 248, 186]
22
22
 
23
- # Constructs a new client
23
+ # Constructs a new client.
24
24
  def initialize
25
25
  @cache = LRUCache.new ttl: CACHE_TTL, soft_ttl: CACHE_SOFT_TTL
26
26
  @http = Net::HTTP.new API_BASE_URI.host, API_BASE_URI.port
27
27
  end
28
28
 
29
- # Returns a schedule for the given date
29
+ # Returns a schedule for the provided channels the given date
30
30
  #
31
31
  # @param date A date
32
32
  # @param channels A list of channel ids to request schedules for
33
+ # @return [Array<Schedule>] the list of schedules
33
34
  def schedules_for date, channels = []
34
35
  return nil unless date.is_a? Date
35
36
 
@@ -44,7 +45,11 @@ module TVTid
44
45
 
45
46
  json_data.map do |schedule|
46
47
  channel = channels.find{|channel| channel.id == schedule['id']}
47
- programs = schedule['programs'].map{|program| Program.from_json program }
48
+ programs = schedule['programs'].map do |program|
49
+ program = Program.from_json program
50
+ program.channel_id = schedule['id']
51
+ program
52
+ end
48
53
  programs.sort!{|a, b| a.start_time <=> b.start_time }
49
54
 
50
55
  Schedule.new channel, programs
@@ -54,7 +59,7 @@ module TVTid
54
59
 
55
60
  # Returns a list of schedules for today
56
61
  #
57
- # This is the same as using `schedules_for Date.today`
62
+ # This is equivalent to using `chedules_for Date.today`
58
63
  def schedules_for_today channels = []
59
64
  schedules_for Date.today, channels
60
65
  end
@@ -76,5 +81,18 @@ module TVTid
76
81
  json_data.map{|json_channel_data| Channel.from_json json_channel_data }
77
82
  end
78
83
  end
84
+
85
+ # Retrieves program details and updates the given program object.
86
+ #
87
+ # @return [Program] the program
88
+ def get_program_details! program
89
+ response = @http.get "/api/tvtid/v1/channels/#{program.channel_id}/programs/#{program.id}", HTTP_REQUEST_HEADERS
90
+
91
+ if response.code == '200'
92
+ program.parse_json! MultiJson.load(response.body)
93
+ end
94
+
95
+ program
96
+ end
79
97
  end
80
98
  end
@@ -1,32 +1,34 @@
1
1
  module TVTid
2
2
  class Program
3
- # The id of the program.
3
+ # @return [Numeric] the id of the program.
4
4
  attr_reader :id
5
- # The title of the program.
5
+ # @return [String] the title of the program.
6
6
  attr_reader :title
7
- # The time the program starts at.
7
+ # @return [DateTime] the time the program starts at.
8
8
  attr_accessor :start_time
9
- # The time the program stops at.
9
+ # @return [DateTime] the time the program ends at.
10
10
  attr_accessor :stop_time
11
- # A url where the user can see more information about the program.
11
+ # @return [String] a URL to where the user can see more information about
12
+ # the program.
12
13
  attr_accessor :url
13
- # The ID of the channel.
14
+ # @return [Numeric] the ID of the channel.
14
15
  attr_accessor :channel_id
15
- # The category of the program.
16
+ # @return [String] the category of the program.
16
17
  attr_accessor :category
17
- # The description of the program.
18
+ # @return [String] the description of the program.
18
19
  attr_accessor :description
19
- # The original non-localized title of the program.
20
+ # @return [String] the original non-localized title of the program.
20
21
  attr_accessor :original_title
21
- # The year of production of the program.
22
+ # @return [Numeric] the year of production of the program.
22
23
  attr_accessor :production_year
23
- # The production country of the program.
24
+ # @return [String] the production country of the program.
24
25
  attr_accessor :production_country
25
- # Teaser text for the program.
26
+ # @return [String] the teaser text of the program.
26
27
  attr_accessor :teaser
27
- # Unique series id if the program is a series.
28
+ # @return [Numeric] a unique series id if the program is a series.
28
29
  attr_accessor :series_id
29
- # Episode and season information if the program is a series.
30
+ # @return [Hash, nil] episode and season information if the program is a
31
+ # series.
30
32
  attr_accessor :series_info
31
33
 
32
34
  # Constructs a new `Program` with an `id` and a `title`.
@@ -36,6 +38,8 @@ module TVTid
36
38
  end
37
39
 
38
40
  # Updates the program information from a json object.
41
+ #
42
+ # @param json [Hash] Parsed JSON object
39
43
  def parse_json! json
40
44
  @start_time = Time.at(json['start']).to_datetime
41
45
  @stop_time = Time.at(json['stop']).to_datetime
@@ -52,7 +56,9 @@ module TVTid
52
56
 
53
57
  # Constructs a `Program` from a json object.
54
58
  #
55
- # @returns Program if json object has an `id` and a `title` - nil otherwise.
59
+ # @param json [Hash] Parsed JSON object
60
+ # @return [Program, nil] program if the given `json` object has an `id`
61
+ # and a `title` attribute, nil otherwise.
56
62
  def self.from_json json
57
63
  return nil unless json['id'] and json['title']
58
64
 
@@ -1,19 +1,23 @@
1
1
  module TVTid
2
2
  class Schedule
3
- # The channel the schedule belongs to.
3
+ # @return [Channel] the channel the schedule belongs to.
4
4
  attr_reader :channel
5
- # The list of programs in the schedule.
5
+ # @return [Array<Program>] the list of programs in the schedule.
6
6
  attr_reader :programs
7
7
 
8
- # Constructs a new schedule for a `channel`.
8
+ # Constructs a new schedule for a channel.
9
+ #
10
+ # @param channel [Channel] the parent channel
11
+ # @param programs [Array<Program>] a list of programs
9
12
  def initialize channel, programs = []
10
13
  @channel = channel
11
14
  @programs = programs
12
15
  end
13
16
 
14
- # Get the previous, current and upcoming programs at a given `time`.
17
+ # Returns the previous, current and upcoming programs at a given `time`.
15
18
  #
16
- # @returns [previous<Array>, current<Program>, upcoming<Array>]
19
+ # @return [(Array<Program>, Program, Array<Program>)] the previous, the
20
+ # current and the upcoming programs relative to the given `time`.
17
21
  def at time
18
22
  cur_idx = 0
19
23
 
@@ -29,9 +33,8 @@ module TVTid
29
33
  end
30
34
  end
31
35
 
32
- # Returns the previous, current and upcoming programs.
33
- #
34
- # @see at
36
+ # @return [(Array<Program>, Program, Array<Program>)] the previous, the
37
+ # current and the upcoming programs relative to the current time.
35
38
  def current
36
39
  self.at DateTime.now
37
40
  end
@@ -1,3 +1,3 @@
1
1
  module TVTid
2
- Version = '0.2'
2
+ Version = '0.3'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tvtid
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: '0.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikkel Kroman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-27 00:00:00.000000000 Z
11
+ date: 2017-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -52,6 +52,120 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '2.18'
55
+ - !ruby/object:Gem::Dependency
56
+ name: vcr
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 3.0.3
65
+ type: :development
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - "~>"
70
+ - !ruby/object:Gem::Version
71
+ version: '3.0'
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 3.0.3
75
+ - !ruby/object:Gem::Dependency
76
+ name: webmock
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '2.3'
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: 2.3.2
85
+ type: :development
86
+ prerelease: false
87
+ version_requirements: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - "~>"
90
+ - !ruby/object:Gem::Version
91
+ version: '2.3'
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: 2.3.2
95
+ - !ruby/object:Gem::Dependency
96
+ name: rspec
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - "~>"
100
+ - !ruby/object:Gem::Version
101
+ version: '3.5'
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: 3.5.0
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: '3.5'
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: 3.5.0
115
+ - !ruby/object:Gem::Dependency
116
+ name: rspec-its
117
+ requirement: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - "~>"
120
+ - !ruby/object:Gem::Version
121
+ version: '1.2'
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: 1.2.0
125
+ type: :development
126
+ prerelease: false
127
+ version_requirements: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '1.2'
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: 1.2.0
135
+ - !ruby/object:Gem::Dependency
136
+ name: guard
137
+ requirement: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - "~>"
140
+ - !ruby/object:Gem::Version
141
+ version: '2.14'
142
+ type: :development
143
+ prerelease: false
144
+ version_requirements: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - "~>"
147
+ - !ruby/object:Gem::Version
148
+ version: '2.14'
149
+ - !ruby/object:Gem::Dependency
150
+ name: guard-rspec
151
+ requirement: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - "~>"
154
+ - !ruby/object:Gem::Version
155
+ version: '4.7'
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: 4.7.3
159
+ type: :development
160
+ prerelease: false
161
+ version_requirements: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - "~>"
164
+ - !ruby/object:Gem::Version
165
+ version: '4.7'
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: 4.7.3
55
169
  description:
56
170
  email: mk@uplink.io
57
171
  executables: []
@@ -59,6 +173,7 @@ extensions: []
59
173
  extra_rdoc_files: []
60
174
  files:
61
175
  - ".yardopts"
176
+ - LICENSE
62
177
  - README.md
63
178
  - library/tvtid.rb
64
179
  - library/tvtid/category.rb
@@ -79,7 +194,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
79
194
  requirements:
80
195
  - - ">="
81
196
  - !ruby/object:Gem::Version
82
- version: 1.9.1
197
+ version: '2.3'
83
198
  required_rubygems_version: !ruby/object:Gem::Requirement
84
199
  requirements:
85
200
  - - ">="