riksteatern 0.0.1
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/.gitignore +17 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +81 -0
- data/Rakefile +17 -0
- data/lib/riksteatern.rb +36 -0
- data/lib/riksteatern/api.rb +64 -0
- data/lib/riksteatern/config.rb +19 -0
- data/lib/riksteatern/errors.rb +6 -0
- data/lib/riksteatern/event.rb +57 -0
- data/lib/riksteatern/http.rb +50 -0
- data/lib/riksteatern/producer.rb +15 -0
- data/lib/riksteatern/production.rb +59 -0
- data/lib/riksteatern/venue.rb +57 -0
- data/lib/riksteatern/venue/accessibility.rb +33 -0
- data/lib/riksteatern/venue/address.rb +27 -0
- data/lib/riksteatern/venue/location.rb +18 -0
- data/lib/riksteatern/version.rb +5 -0
- data/riksteatern.gemspec +23 -0
- data/spec/fixtures/lokal/0180126.json +54 -0
- data/spec/fixtures/lokal/5015846.json +54 -0
- data/spec/fixtures/produktion/1674.json +29 -0
- data/spec/fixtures/produktion/314.json +29 -0
- data/spec/fixtures/repertoar/992308.json +23 -0
- data/spec/riksteatern/api_spec.rb +44 -0
- data/spec/riksteatern/config_spec.rb +42 -0
- data/spec/riksteatern/errors_spec.rb +10 -0
- data/spec/riksteatern/event_spec.rb +44 -0
- data/spec/riksteatern/http_spec.rb +41 -0
- data/spec/riksteatern/producent_spec.rb +27 -0
- data/spec/riksteatern/production_spec.rb +29 -0
- data/spec/riksteatern/venue_spec.rb +39 -0
- data/spec/riksteatern/version_spec.rb +11 -0
- data/spec/riksteatern_spec.rb +51 -0
- data/spec/spec_helper.rb +44 -0
- metadata +138 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require_relative '../spec_helper'
|
|
4
|
+
|
|
5
|
+
describe "Event" do
|
|
6
|
+
subject { Riksteatern::Event }
|
|
7
|
+
|
|
8
|
+
let(:under_hatten) { subject.new(under_hatten_data) }
|
|
9
|
+
let(:under_hatten_data) { parsed_fixture('repertoar/992308') }
|
|
10
|
+
|
|
11
|
+
describe "find" do
|
|
12
|
+
it "finds a event based on id" do
|
|
13
|
+
with_data([under_hatten_data]) do
|
|
14
|
+
event = subject.find(992308)
|
|
15
|
+
last_params.must_equal eventId: 992308
|
|
16
|
+
event.name.must_equal 'Under hatten'
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "returns nil if passed an empty array" do
|
|
21
|
+
with_data([]) do
|
|
22
|
+
subject.find(123).must_be_nil
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
describe "all" do
|
|
28
|
+
it "returns a list of events" do
|
|
29
|
+
with_data([under_hatten_data, {}]) do
|
|
30
|
+
events = subject.all
|
|
31
|
+
events.size.must_equal 2
|
|
32
|
+
events.first.venue_name.must_equal 'Folkets Hus, Idun'
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
describe "get_data" do
|
|
38
|
+
it "returns repertoires using the api" do
|
|
39
|
+
Riksteatern.api.stub(:repertoires, 'foobar') do
|
|
40
|
+
subject.get_data.must_equal 'foobar'
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require_relative '../spec_helper'
|
|
4
|
+
|
|
5
|
+
describe "HTTP" do
|
|
6
|
+
subject { Riksteatern::HTTP }
|
|
7
|
+
|
|
8
|
+
let(:uri) { URI.parse('http://example.local/') }
|
|
9
|
+
|
|
10
|
+
describe "get" do
|
|
11
|
+
it "returns the response body if the response code is 200" do
|
|
12
|
+
mock = MiniTest::Mock.new.expect(:code, '200').
|
|
13
|
+
expect(:code, '200').
|
|
14
|
+
expect(:body, 'foobar')
|
|
15
|
+
|
|
16
|
+
subject.stub(:make_request, mock) do
|
|
17
|
+
subject.get(uri).must_equal 'foobar'
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
mock.verify
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "raises an exception if the response code is 401" do
|
|
24
|
+
mock = MiniTest::Mock.new.expect(:code, '401')
|
|
25
|
+
|
|
26
|
+
subject.stub(:make_request, mock) do
|
|
27
|
+
->{ subject.get(uri) }.must_raise Riksteatern::UnauthorizedUser
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
mock.verify
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "returns nil otherwise" do
|
|
34
|
+
mock = MiniTest::Mock.new.expect(:code, '500').expect(:code, '500')
|
|
35
|
+
|
|
36
|
+
subject.stub(:make_request, mock) { subject.get(uri).must_be_nil }
|
|
37
|
+
|
|
38
|
+
mock.verify
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require_relative '../spec_helper'
|
|
4
|
+
|
|
5
|
+
describe "Producer" do
|
|
6
|
+
subject { Riksteatern::Producer }
|
|
7
|
+
|
|
8
|
+
let(:example_data) {
|
|
9
|
+
{
|
|
10
|
+
'producerId' => 123,
|
|
11
|
+
'producerName' => 'foo',
|
|
12
|
+
'mainContactId' => 456,
|
|
13
|
+
'producerHomepage' => 'http://producer.url/',
|
|
14
|
+
'producerLogotype' => 'http://producer.url/logotype.png'
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
it "has the attributes id, name, main_contact_id, homepage and logotype" do
|
|
19
|
+
subject.new(example_data).tap do |p|
|
|
20
|
+
p.id.must_equal example_data['producerId']
|
|
21
|
+
p.name.must_equal example_data['producerName']
|
|
22
|
+
p.main_contact_id.must_equal example_data['mainContactId']
|
|
23
|
+
p.homepage.must_equal example_data['producerHomepage']
|
|
24
|
+
p.logotype.must_equal example_data['producerLogotype']
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require_relative '../spec_helper'
|
|
4
|
+
|
|
5
|
+
describe "Production" do
|
|
6
|
+
subject { Riksteatern::Production }
|
|
7
|
+
|
|
8
|
+
let(:hamster) {
|
|
9
|
+
subject.new parsed_fixture('produktion/314')
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
describe "find" do
|
|
13
|
+
it "finds a production based on id" do
|
|
14
|
+
with_data([parsed_fixture('produktion/314')]) do
|
|
15
|
+
l = subject.find(314)
|
|
16
|
+
|
|
17
|
+
last_params.must_equal productionId: 314
|
|
18
|
+
|
|
19
|
+
l.name.must_equal 'Kan man älska en hamster?'
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "returns nil if passed an empty array" do
|
|
24
|
+
with_data([]) do
|
|
25
|
+
subject.find(123).must_be_nil
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require_relative '../spec_helper'
|
|
4
|
+
|
|
5
|
+
describe "Venue" do
|
|
6
|
+
subject { Riksteatern::Venue }
|
|
7
|
+
|
|
8
|
+
let(:folkets_hus) { subject.new(folkets_hus_data) }
|
|
9
|
+
let(:folkets_hus_data) { parsed_fixture('lokal/5015846') }
|
|
10
|
+
let(:finlandsinstitutet_data) { parsed_fixture('lokal/0180126') }
|
|
11
|
+
|
|
12
|
+
describe "find" do
|
|
13
|
+
it "finds a production based on id" do
|
|
14
|
+
with_data([folkets_hus_data]) do
|
|
15
|
+
l = subject.find(123)
|
|
16
|
+
|
|
17
|
+
last_params.must_equal venueId: 123
|
|
18
|
+
|
|
19
|
+
l.name.must_equal 'Folkets Hus, Idun'
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "returns nil if no venue was found" do
|
|
24
|
+
with_data([]) { subject.find(123).must_be_nil }
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
describe "all" do
|
|
29
|
+
it "returns an array of venues" do
|
|
30
|
+
with_data([folkets_hus_data, finlandsinstitutet_data]) do
|
|
31
|
+
venues = subject.all
|
|
32
|
+
|
|
33
|
+
venues.size.must_equal 2
|
|
34
|
+
venues.first.name.must_equal 'Folkets Hus, Idun'
|
|
35
|
+
venues.last.name.must_equal 'Finlandsinstitutet, Sibeliussalen'
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require_relative 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe "Riksteatern" do
|
|
6
|
+
subject { Riksteatern }
|
|
7
|
+
|
|
8
|
+
describe "configure" do
|
|
9
|
+
it "can be configured" do
|
|
10
|
+
subject.config.base_url.must_equal 'https://riksteatern.se:8181/api'
|
|
11
|
+
|
|
12
|
+
subject.configure do |c|
|
|
13
|
+
c.base_url = 'changed.url'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
subject.config.base_url.must_equal 'changed.url'
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "can change the json parser lamda" do
|
|
20
|
+
subject.configure do |c|
|
|
21
|
+
c.json_parser = ->{ 'foo' }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
subject.config.json_parser.call.must_equal 'foo'
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
describe "config" do
|
|
29
|
+
it "returns a (default) config object" do
|
|
30
|
+
subject.config.must_be_instance_of Riksteatern::Config
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
describe "api" do
|
|
35
|
+
it "returns a (default) api object" do
|
|
36
|
+
subject.api.must_be_instance_of Riksteatern::Api
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
describe "account" do
|
|
41
|
+
it "configures the username and password" do
|
|
42
|
+
username = 'foo@bar.biz'
|
|
43
|
+
password = 'FooBar'
|
|
44
|
+
|
|
45
|
+
r = subject.account(username, password)
|
|
46
|
+
|
|
47
|
+
r.config.username.must_equal username
|
|
48
|
+
r.config.password.must_equal password
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'minitest/spec'
|
|
4
|
+
require 'minitest/pride'
|
|
5
|
+
require 'minitest/autorun'
|
|
6
|
+
|
|
7
|
+
require_relative '../lib/riksteatern'
|
|
8
|
+
|
|
9
|
+
class BounceURI
|
|
10
|
+
def self.get(uri)
|
|
11
|
+
uri
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
Riksteatern.configure do |c|
|
|
16
|
+
c.http_client = BounceURI
|
|
17
|
+
|
|
18
|
+
c.username = 'foo'
|
|
19
|
+
c.password = 'bar'
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
$loaded_fixtures = {}
|
|
24
|
+
|
|
25
|
+
def fixture(name)
|
|
26
|
+
$loaded_fixtures[name] ||= IO.read("spec/fixtures/#{name}.json")
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def parsed_fixture(name)
|
|
30
|
+
JSON.parse fixture(name)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def with_fixture(name, &block)
|
|
34
|
+
Riksteatern.api.stub(:get_json, parsed_fixture(name), &block)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def with_data(data, &block)
|
|
38
|
+
@last_params = nil
|
|
39
|
+
subject.stub :get_data, ->(params){ @last_params = params; data }, &block
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def last_params
|
|
43
|
+
@last_params
|
|
44
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: riksteatern
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Peter Hellberg
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2013-03-17 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ~>
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.3'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ~>
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.3'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - '>='
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :development
|
|
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: minitest
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - '>='
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - '>='
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
description:
|
|
56
|
+
email:
|
|
57
|
+
- peter@c7.se
|
|
58
|
+
executables: []
|
|
59
|
+
extensions: []
|
|
60
|
+
extra_rdoc_files: []
|
|
61
|
+
files:
|
|
62
|
+
- .gitignore
|
|
63
|
+
- .travis.yml
|
|
64
|
+
- Gemfile
|
|
65
|
+
- LICENSE.txt
|
|
66
|
+
- README.md
|
|
67
|
+
- Rakefile
|
|
68
|
+
- lib/riksteatern.rb
|
|
69
|
+
- lib/riksteatern/api.rb
|
|
70
|
+
- lib/riksteatern/config.rb
|
|
71
|
+
- lib/riksteatern/errors.rb
|
|
72
|
+
- lib/riksteatern/event.rb
|
|
73
|
+
- lib/riksteatern/http.rb
|
|
74
|
+
- lib/riksteatern/producer.rb
|
|
75
|
+
- lib/riksteatern/production.rb
|
|
76
|
+
- lib/riksteatern/venue.rb
|
|
77
|
+
- lib/riksteatern/venue/accessibility.rb
|
|
78
|
+
- lib/riksteatern/venue/address.rb
|
|
79
|
+
- lib/riksteatern/venue/location.rb
|
|
80
|
+
- lib/riksteatern/version.rb
|
|
81
|
+
- riksteatern.gemspec
|
|
82
|
+
- spec/fixtures/lokal/0180126.json
|
|
83
|
+
- spec/fixtures/lokal/5015846.json
|
|
84
|
+
- spec/fixtures/produktion/1674.json
|
|
85
|
+
- spec/fixtures/produktion/314.json
|
|
86
|
+
- spec/fixtures/repertoar/992308.json
|
|
87
|
+
- spec/riksteatern/api_spec.rb
|
|
88
|
+
- spec/riksteatern/config_spec.rb
|
|
89
|
+
- spec/riksteatern/errors_spec.rb
|
|
90
|
+
- spec/riksteatern/event_spec.rb
|
|
91
|
+
- spec/riksteatern/http_spec.rb
|
|
92
|
+
- spec/riksteatern/producent_spec.rb
|
|
93
|
+
- spec/riksteatern/production_spec.rb
|
|
94
|
+
- spec/riksteatern/venue_spec.rb
|
|
95
|
+
- spec/riksteatern/version_spec.rb
|
|
96
|
+
- spec/riksteatern_spec.rb
|
|
97
|
+
- spec/spec_helper.rb
|
|
98
|
+
homepage: https://github.com/peterhellberg/riksteatern
|
|
99
|
+
licenses:
|
|
100
|
+
- MIT
|
|
101
|
+
metadata: {}
|
|
102
|
+
post_install_message:
|
|
103
|
+
rdoc_options: []
|
|
104
|
+
require_paths:
|
|
105
|
+
- lib
|
|
106
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - '>='
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: '0'
|
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
|
+
requirements:
|
|
113
|
+
- - '>='
|
|
114
|
+
- !ruby/object:Gem::Version
|
|
115
|
+
version: '0'
|
|
116
|
+
requirements: []
|
|
117
|
+
rubyforge_project:
|
|
118
|
+
rubygems_version: 2.0.3
|
|
119
|
+
signing_key:
|
|
120
|
+
specification_version: 4
|
|
121
|
+
summary: Ruby client for the Riksteatern API
|
|
122
|
+
test_files:
|
|
123
|
+
- spec/fixtures/lokal/0180126.json
|
|
124
|
+
- spec/fixtures/lokal/5015846.json
|
|
125
|
+
- spec/fixtures/produktion/1674.json
|
|
126
|
+
- spec/fixtures/produktion/314.json
|
|
127
|
+
- spec/fixtures/repertoar/992308.json
|
|
128
|
+
- spec/riksteatern/api_spec.rb
|
|
129
|
+
- spec/riksteatern/config_spec.rb
|
|
130
|
+
- spec/riksteatern/errors_spec.rb
|
|
131
|
+
- spec/riksteatern/event_spec.rb
|
|
132
|
+
- spec/riksteatern/http_spec.rb
|
|
133
|
+
- spec/riksteatern/producent_spec.rb
|
|
134
|
+
- spec/riksteatern/production_spec.rb
|
|
135
|
+
- spec/riksteatern/venue_spec.rb
|
|
136
|
+
- spec/riksteatern/version_spec.rb
|
|
137
|
+
- spec/riksteatern_spec.rb
|
|
138
|
+
- spec/spec_helper.rb
|