ted_api 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.
Files changed (75) hide show
  1. data/.gitignore +17 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE.txt +22 -0
  4. data/README.md +56 -0
  5. data/Rakefile +8 -0
  6. data/lib/faraday/response/raise_ted_api_error.rb +43 -0
  7. data/lib/ted_api.rb +20 -0
  8. data/lib/ted_api/client.rb +39 -0
  9. data/lib/ted_api/client/countries.rb +18 -0
  10. data/lib/ted_api/client/events.rb +18 -0
  11. data/lib/ted_api/client/languages.rb +18 -0
  12. data/lib/ted_api/client/quotes.rb +18 -0
  13. data/lib/ted_api/client/rating_words.rb +18 -0
  14. data/lib/ted_api/client/speakers.rb +18 -0
  15. data/lib/ted_api/client/tags.rb +18 -0
  16. data/lib/ted_api/client/talks.rb +26 -0
  17. data/lib/ted_api/client/themes.rb +18 -0
  18. data/lib/ted_api/configuration.rb +54 -0
  19. data/lib/ted_api/connection.rb +30 -0
  20. data/lib/ted_api/error.rb +34 -0
  21. data/lib/ted_api/request.rb +34 -0
  22. data/lib/ted_api/version.rb +3 -0
  23. data/spec/faraday/response_spec.rb +35 -0
  24. data/spec/fixtures/countries.json +1 -0
  25. data/spec/fixtures/countries.xml +109 -0
  26. data/spec/fixtures/country.json +1 -0
  27. data/spec/fixtures/country.xml +8 -0
  28. data/spec/fixtures/event.json +1 -0
  29. data/spec/fixtures/event.xml +12 -0
  30. data/spec/fixtures/events.json +1 -0
  31. data/spec/fixtures/events.xml +189 -0
  32. data/spec/fixtures/language.json +1 -0
  33. data/spec/fixtures/language.xml +8 -0
  34. data/spec/fixtures/languages.json +1 -0
  35. data/spec/fixtures/languages.xml +106 -0
  36. data/spec/fixtures/quote.json +1 -0
  37. data/spec/fixtures/quote.xml +14 -0
  38. data/spec/fixtures/quotes.json +2 -0
  39. data/spec/fixtures/quotes.xml +230 -0
  40. data/spec/fixtures/rating_word.json +1 -0
  41. data/spec/fixtures/rating_word.xml +7 -0
  42. data/spec/fixtures/rating_words.json +1 -0
  43. data/spec/fixtures/rating_words.xml +65 -0
  44. data/spec/fixtures/speaker.json +1 -0
  45. data/spec/fixtures/speaker.xml +16 -0
  46. data/spec/fixtures/speakers.json +1 -0
  47. data/spec/fixtures/speakers.xml +269 -0
  48. data/spec/fixtures/speakers_by_talk.json +1 -0
  49. data/spec/fixtures/subtitles.json +2 -0
  50. data/spec/fixtures/tag.json +1 -0
  51. data/spec/fixtures/tag.xml +11 -0
  52. data/spec/fixtures/tags.json +1 -0
  53. data/spec/fixtures/tags.xml +169 -0
  54. data/spec/fixtures/talk.json +1 -0
  55. data/spec/fixtures/talk.xml +302 -0
  56. data/spec/fixtures/talks.json +1 -0
  57. data/spec/fixtures/talks.xml +249 -0
  58. data/spec/fixtures/theme.json +1 -0
  59. data/spec/fixtures/theme.xml +19 -0
  60. data/spec/fixtures/themes.json +1 -0
  61. data/spec/fixtures/themes.xml +294 -0
  62. data/spec/spec_helper.rb +38 -0
  63. data/spec/ted_api/client/countries_spec.rb +46 -0
  64. data/spec/ted_api/client/events_spec.rb +46 -0
  65. data/spec/ted_api/client/languages_spec.rb +46 -0
  66. data/spec/ted_api/client/quotes_spec.rb +46 -0
  67. data/spec/ted_api/client/rating_words_spec.rb +46 -0
  68. data/spec/ted_api/client/speakers_spec.rb +46 -0
  69. data/spec/ted_api/client/tags_spec.rb +46 -0
  70. data/spec/ted_api/client/talks_spec.rb +78 -0
  71. data/spec/ted_api/client/themes_spec.rb +46 -0
  72. data/spec/ted_api/client_spec.rb +26 -0
  73. data/spec/ted_api_spec.rb +21 -0
  74. data/ted_api.gemspec +33 -0
  75. metadata +347 -0
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe TedApi::Client::Languages do
4
+
5
+ after(:each) do
6
+ TedApi.reset
7
+ end
8
+
9
+ # JSON Tests:
10
+
11
+ it "should list Ted events in json" do
12
+ @client = TedApi::Client.new(api_key: 'foo')
13
+ stub_get("languages.json?api-key=foo").
14
+ to_return(:body => fixture("languages.json"))
15
+ response = @client.languages
16
+ response.languages.first.language.language_code.should == 'af'
17
+ end
18
+
19
+ it "should return a specific Ted event in json" do
20
+ @client = TedApi::Client.new(api_key: 'foo')
21
+ stub_get("languages/af.json?api-key=foo").
22
+ to_return(:body => fixture("language.json"))
23
+ response = @client.languages('af')
24
+ response.language.language_code.should == 'af'
25
+ end
26
+
27
+ # XML Tests:
28
+
29
+ it "should list Ted events in xml" do
30
+ @client = TedApi::Client.new(api_key: 'foo', response_format: 'xml')
31
+ stub_get("languages.xml?api-key=foo").
32
+ to_return(:body => fixture("languages.xml"))
33
+ response = @client.languages
34
+ response.languages.first.first.should == 'language'
35
+ end
36
+
37
+ it "should return a specific Ted event in xml" do
38
+ @client = TedApi::Client.new(api_key: 'foo', response_format: 'xml')
39
+ stub_get("languages/af.xml?api-key=foo").
40
+ to_return(:body => fixture("language.xml"))
41
+ response = @client.languages('af')
42
+ response.language.language_code.should == 'af'
43
+ end
44
+
45
+
46
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe TedApi::Client::Quotes do
4
+
5
+ after(:each) do
6
+ TedApi.reset
7
+ end
8
+
9
+ # JSON Tests:
10
+
11
+ it "should list Ted quotes in json" do
12
+ @client = TedApi::Client.new(api_key: 'foo')
13
+ stub_get("quotes.json?api-key=foo").
14
+ to_return(:body => fixture("quotes.json"))
15
+ response = @client.quotes
16
+ response.quotes.first.quote.slug.should == 'around_the_world_women_and_children_spend_40_billion_hours'
17
+ end
18
+
19
+ it "should return a specific Ted quote in json" do
20
+ @client = TedApi::Client.new(api_key: 'foo')
21
+ stub_get("quotes/1.json?api-key=foo").
22
+ to_return(:body => fixture("quote.json"))
23
+ response = @client.quotes('1')
24
+ response.quote.slug.should == 'around_the_world_women_and_children_spend_40_billion_hours'
25
+ end
26
+
27
+ # XML Tests:
28
+
29
+ it "should list Ted events in xml" do
30
+ @client = TedApi::Client.new(api_key: 'foo', response_format: 'xml')
31
+ stub_get("quotes.xml?api-key=foo").
32
+ to_return(:body => fixture("quotes.xml"))
33
+ response = @client.quotes
34
+ response.quotes.first.first.should == 'quote'
35
+ end
36
+
37
+ it "should return a specific Ted event in xml" do
38
+ @client = TedApi::Client.new(api_key: 'foo', response_format: 'xml')
39
+ stub_get("quotes/1.xml?api-key=foo").
40
+ to_return(:body => fixture("quote.xml"))
41
+ response = @client.quotes('1')
42
+ response.quote.slug.should == 'around_the_world_women_and_children_spend_40_billion_hours'
43
+ end
44
+
45
+
46
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe TedApi::Client::RatingWords do
4
+
5
+ after(:each) do
6
+ TedApi.reset
7
+ end
8
+
9
+ # JSON Tests:
10
+
11
+ it "should list rating words in json" do
12
+ @client = TedApi::Client.new(api_key: 'foo')
13
+ stub_get("rating_words.json?api-key=foo").
14
+ to_return(:body => fixture("rating_words.json"))
15
+ response = @client.rating_words
16
+ response.rating_words.first.rating_word.name.should == 'Beautiful'
17
+ end
18
+
19
+ it "should return a specific rating word in json" do
20
+ @client = TedApi::Client.new(api_key: 'foo')
21
+ stub_get("rating_words/1.json?api-key=foo").
22
+ to_return(:body => fixture("rating_word.json"))
23
+ response = @client.rating_words('1')
24
+ response.rating_word.name.should == 'Beautiful'
25
+ end
26
+
27
+ # XML Tests:
28
+
29
+ it "should list rating words in xml" do
30
+ @client = TedApi::Client.new(api_key: 'foo', response_format: 'xml')
31
+ stub_get("rating_words.xml?api-key=foo").
32
+ to_return(:body => fixture("rating_words.xml"))
33
+ response = @client.rating_words
34
+ response.rating_words.first.first.should == 'rating_word'
35
+ end
36
+
37
+ it "should return a specific rating word in xml" do
38
+ @client = TedApi::Client.new(api_key: 'foo', response_format: 'xml')
39
+ stub_get("rating_words/1.xml?api-key=foo").
40
+ to_return(:body => fixture("rating_word.xml"))
41
+ response = @client.rating_words('1')
42
+ response.rating_word.name.should == 'Beautiful'
43
+ end
44
+
45
+
46
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe TedApi::Client::Speakers do
4
+
5
+ after(:each) do
6
+ TedApi.reset
7
+ end
8
+
9
+ # JSON Tests:
10
+
11
+ it "should list speakers in json" do
12
+ @client = TedApi::Client.new(api_key: 'foo')
13
+ stub_get("speakers.json?api-key=foo").
14
+ to_return(:body => fixture("speakers.json"))
15
+ response = @client.speakers
16
+ response.speakers.first.speaker.description.should == 'Climate-change prophet'
17
+ end
18
+
19
+ it "should return a specific speaker in json" do
20
+ @client = TedApi::Client.new(api_key: 'foo')
21
+ stub_get("speakers/2.json?api-key=foo").
22
+ to_return(:body => fixture("speaker.json"))
23
+ response = @client.speakers('2')
24
+ response.speaker.description.should == 'Climate-change prophet'
25
+ end
26
+
27
+ # XML Tests:
28
+
29
+ it "should list speakers in xml" do
30
+ @client = TedApi::Client.new(api_key: 'foo', response_format: 'xml')
31
+ stub_get("speakers.xml?api-key=foo").
32
+ to_return(:body => fixture("speakers.xml"))
33
+ response = @client.speakers
34
+ response.speakers.first.first.should == 'speaker'
35
+ end
36
+
37
+ it "should return a specific theme in xml" do
38
+ @client = TedApi::Client.new(api_key: 'foo', response_format: 'xml')
39
+ stub_get("speakers/2.xml?api-key=foo").
40
+ to_return(:body => fixture("speaker.xml"))
41
+ response = @client.speakers('2')
42
+ response.speaker.description.should == 'Climate-change prophet'
43
+ end
44
+
45
+
46
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe TedApi::Client::Tags do
4
+
5
+ after(:each) do
6
+ TedApi.reset
7
+ end
8
+
9
+ # JSON Tests:
10
+
11
+ it "should list tags in json" do
12
+ @client = TedApi::Client.new(api_key: 'foo')
13
+ stub_get("tags.json?api-key=foo").
14
+ to_return(:body => fixture("tags.json"))
15
+ response = @client.tags
16
+ response.tags.first.tag.name.should == 'standard'
17
+ end
18
+
19
+ it "should return a specific tag in json" do
20
+ @client = TedApi::Client.new(api_key: 'foo')
21
+ stub_get("tags/1.json?api-key=foo").
22
+ to_return(:body => fixture("tag.json"))
23
+ response = @client.tags('1')
24
+ response.tag.name.should == 'standard'
25
+ end
26
+
27
+ # XML Tests:
28
+
29
+ it "should list speakers in xml" do
30
+ @client = TedApi::Client.new(api_key: 'foo', response_format: 'xml')
31
+ stub_get("tags.xml?api-key=foo").
32
+ to_return(:body => fixture("tags.xml"))
33
+ response = @client.tags
34
+ response.tags.first.first.should == 'tag'
35
+ end
36
+
37
+ it "should return a specific theme in xml" do
38
+ @client = TedApi::Client.new(api_key: 'foo', response_format: 'xml')
39
+ stub_get("tags/1.xml?api-key=foo").
40
+ to_return(:body => fixture("tag.xml"))
41
+ response = @client.tags('1')
42
+ response.tag.name.should == 'standard'
43
+ end
44
+
45
+
46
+ end
@@ -0,0 +1,78 @@
1
+ require 'spec_helper'
2
+
3
+ describe TedApi::Client::Talks do
4
+
5
+ after(:each) do
6
+ TedApi.reset
7
+ end
8
+
9
+ # JSON Tests:
10
+
11
+ it "should list Ted talks in json" do
12
+ @client = TedApi::Client.new(api_key: 'foo')
13
+ stub_get("talks.json?api-key=foo").
14
+ to_return(:body => fixture("talks.json"))
15
+ response = @client.talks
16
+ response.talks.first.talk.name.should == "Al Gore: Averting the climate crisis"
17
+ end
18
+
19
+ it "should return Ted talks in json raw" do
20
+ @client = TedApi::Client.new(api_key: 'foo')
21
+ stub_get("talks.json?api-key=foo").
22
+ to_return(:body => fixture("talks.json"))
23
+ response = @client.talks(nil, {}, true)
24
+ response.class.name.should == "Faraday::Response"
25
+ end
26
+
27
+ it "should return a specific Ted talk in json" do
28
+ @client = TedApi::Client.new(api_key: 'foo')
29
+ stub_get("talks/1.json?api-key=foo").
30
+ to_return(:body => fixture("talk.json"))
31
+ response = @client.talks('1')
32
+ response.talk.name.should == "Al Gore: Averting the climate crisis"
33
+ end
34
+
35
+ it "should return speakers for a specific Ted talk in json" do
36
+ @client = TedApi::Client.new(api_key: 'foo')
37
+ stub_get("talks/1/speakers.json?api-key=foo").
38
+ to_return(:body => fixture("speakers_by_talk.json"))
39
+ response = @client.speakers_by_talk('1')
40
+ response.speakers.first.speaker.description.should == 'Climate-change prophet'
41
+ end
42
+
43
+ it "should return speakers for a specific Ted talk in json" do
44
+ @client = TedApi::Client.new(api_key: 'foo')
45
+ stub_get("talks/1/subtitles.json?api-key=foo").
46
+ to_return(:body => fixture("subtitles.json"))
47
+ response = @client.subtitles('1')
48
+ response.first.first.should == "0"
49
+ end
50
+
51
+ # XML Tests:
52
+
53
+ it "should list Ted talks in xml" do
54
+ @client = TedApi::Client.new(api_key: 'foo', response_format: 'xml')
55
+ stub_get("talks.xml?api-key=foo").
56
+ to_return(:body => fixture("talks.xml"))
57
+ response = @client.talks
58
+ response.talks.talk.first.name.should == "Al Gore: Averting the climate crisis"
59
+ end
60
+
61
+ it "should return Ted talks in xml raw" do
62
+ @client = TedApi::Client.new(api_key: 'foo', response_format: 'xml')
63
+ stub_get("talks.xml?api-key=foo").
64
+ to_return(:body => fixture("talks.xml"))
65
+ response = @client.talks(nil, {}, true)
66
+ response.class.name.should == "Faraday::Response"
67
+ end
68
+
69
+ it "should return a specific Ted talk in xml" do
70
+ @client = TedApi::Client.new(api_key: 'foo', response_format: 'xml')
71
+ stub_get("talks/1.xml?api-key=foo").
72
+ to_return(:body => fixture("talk.xml"))
73
+ response = @client.talks('1')
74
+ response.talk.name.should == "Al Gore: Averting the climate crisis"
75
+ end
76
+
77
+
78
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe TedApi::Client::Themes do
4
+
5
+ after(:each) do
6
+ TedApi.reset
7
+ end
8
+
9
+ # JSON Tests:
10
+
11
+ it "should list themes in json" do
12
+ @client = TedApi::Client.new(api_key: 'foo')
13
+ stub_get("themes.json?api-key=foo").
14
+ to_return(:body => fixture("themes.json"))
15
+ response = @client.themes
16
+ response.themes.first.theme.slug.should == 'the_creative_spark'
17
+ end
18
+
19
+ it "should return a specific theme in json" do
20
+ @client = TedApi::Client.new(api_key: 'foo')
21
+ stub_get("themes/1.json?api-key=foo").
22
+ to_return(:body => fixture("theme.json"))
23
+ response = @client.themes('1')
24
+ response.theme.slug.should == 'the_creative_spark'
25
+ end
26
+
27
+ # XML Tests:
28
+
29
+ it "should list themes in xml" do
30
+ @client = TedApi::Client.new(api_key: 'foo', response_format: 'xml')
31
+ stub_get("themes.xml?api-key=foo").
32
+ to_return(:body => fixture("themes.xml"))
33
+ response = @client.themes
34
+ response.themes.first.first.should == 'theme'
35
+ end
36
+
37
+ it "should return a specific theme in xml" do
38
+ @client = TedApi::Client.new(api_key: 'foo', response_format: 'xml')
39
+ stub_get("themes/1.xml?api-key=foo").
40
+ to_return(:body => fixture("theme.xml"))
41
+ response = @client.themes('1')
42
+ response.theme.slug.should == 'the_creative_spark'
43
+ end
44
+
45
+
46
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe TedApi::Client do
4
+ it 'should instantiate with api key' do
5
+ proc {
6
+ TedApi::Client.new(api_key: 'foo')
7
+ }.should_not raise_exception
8
+ end
9
+
10
+ describe "api_endpoint" do
11
+ after(:each) do
12
+ TedApi.reset
13
+ end
14
+
15
+ it "should default to https://api.ted.com/" do
16
+ client = TedApi::Client.new
17
+ client.api_endpoint.should == 'https://api.ted.com/'
18
+ end
19
+
20
+ it "should be set " do
21
+ TedApi.api_endpoint = 'http://foo.dev'
22
+ client = TedApi::Client.new
23
+ client.api_endpoint.should == 'http://foo.dev/'
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe TedApi do
5
+ after do
6
+ TedApi.reset
7
+ end
8
+
9
+ describe ".respond_to?" do
10
+ it "should be true if method exists" do
11
+ TedApi.respond_to?(:new, true).should be_true
12
+ end
13
+ end
14
+
15
+ describe ".new" do
16
+ it "should be a TedApi::Client" do
17
+ TedApi.new.should be_a TedApi::Client
18
+ end
19
+ end
20
+
21
+ end
@@ -0,0 +1,33 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ted_api/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "ted_api"
8
+ gem.version = TedApi::VERSION
9
+ gem.authors = ["John Barton"]
10
+ gem.email = ["jb@phy5ics.com"]
11
+ gem.description = %q{A wrapper for the TED Talks API.}
12
+ gem.summary = %q{A wrapper for the TED Talks API that allows for both JSON and XML methods. See http://developer.ted.com/ for more information on the API.}
13
+ gem.homepage = "https://github.com/phy5ics/ted-api"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency 'faraday', '~> 0.8.4'
21
+ gem.add_dependency 'faraday_middleware', '~> 0.8.4'
22
+ gem.add_dependency 'hashie', '~> 1.2'
23
+ gem.add_dependency 'multi_json', '~> 1.3'
24
+ gem.add_dependency 'multi_xml', '~> 0.5.0'
25
+
26
+ gem.add_development_dependency 'json'
27
+ gem.add_development_dependency 'maruku'
28
+ gem.add_development_dependency 'rake'
29
+ gem.add_development_dependency 'rspec'
30
+ gem.add_development_dependency 'simplecov'
31
+ gem.add_development_dependency 'webmock'
32
+
33
+ end