shuffler_fm 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/.gitignore +21 -0
  2. data/.rspec +1 -0
  3. data/.travis.yml +10 -0
  4. data/.yardopts +2 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE +22 -0
  7. data/README.md +121 -0
  8. data/Rakefile +37 -0
  9. data/lib/shuffler_fm/api/artists.rb +53 -0
  10. data/lib/shuffler_fm/api/blogs.rb +52 -0
  11. data/lib/shuffler_fm/api/channels.rb +88 -0
  12. data/lib/shuffler_fm/api/charts.rb +28 -0
  13. data/lib/shuffler_fm/api/genres.rb +28 -0
  14. data/lib/shuffler_fm/api/tracks.rb +33 -0
  15. data/lib/shuffler_fm/api.rb +54 -0
  16. data/lib/shuffler_fm/configuration.rb +44 -0
  17. data/lib/shuffler_fm/errors.rb +37 -0
  18. data/lib/shuffler_fm/http.rb +25 -0
  19. data/lib/shuffler_fm/middleware/error_handler.rb +49 -0
  20. data/lib/shuffler_fm/request.rb +25 -0
  21. data/lib/shuffler_fm/version.rb +3 -0
  22. data/lib/shuffler_fm.rb +67 -0
  23. data/shuffler_fm.gemspec +37 -0
  24. data/spec/config.yml.sample +3 -0
  25. data/spec/fixtures/vcr_cassettes/api.yml +26 -0
  26. data/spec/fixtures/vcr_cassettes/artists.yml +187 -0
  27. data/spec/fixtures/vcr_cassettes/blogs.yml +187 -0
  28. data/spec/fixtures/vcr_cassettes/channels.yml +95 -0
  29. data/spec/fixtures/vcr_cassettes/charts.yml +95 -0
  30. data/spec/fixtures/vcr_cassettes/genres.yml +95 -0
  31. data/spec/fixtures/vcr_cassettes/tracks.yml +95 -0
  32. data/spec/helper.rb +39 -0
  33. data/spec/shuffler_fm/api/artists_spec.rb +25 -0
  34. data/spec/shuffler_fm/api/blogs_spec.rb +25 -0
  35. data/spec/shuffler_fm/api/channels_spec.rb +23 -0
  36. data/spec/shuffler_fm/api/charts_spec.rb +15 -0
  37. data/spec/shuffler_fm/api/genres_spec.rb +15 -0
  38. data/spec/shuffler_fm/api/tracks_spec.rb +15 -0
  39. data/spec/shuffler_fm/api_spec.rb +15 -0
  40. data/spec/shuffler_fm/configuration_spec.rb +9 -0
  41. data/spec/shuffler_fm/middleware/error_handler_spec.rb +29 -0
  42. data/spec/shufflerfm_spec.rb +29 -0
  43. metadata +315 -0
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .rvmrc
7
+ .sublime
8
+ config.yml
9
+ Gemfile.lock
10
+ InstalledFiles
11
+ _yardoc
12
+ coverage
13
+ smoke
14
+ doc/
15
+ lib/bundler/man
16
+ pkg
17
+ rdoc
18
+ spec/reports
19
+ test/tmp
20
+ test/version_tmp
21
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ -r ./spec/helper.rb -c -f documentation
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ script: bundle exec rake --verbose --trace
3
+ matrix:
4
+ allow_failures:
5
+ - rvm: ruby-head
6
+ rvm:
7
+ - 1.8.7
8
+ - 1.9.2
9
+ - 1.9.3
10
+ - ruby-head
data/.yardopts ADDED
@@ -0,0 +1,2 @@
1
+ --no-private --protected --markup markdown lib/**/*.rb - README.md LICENSE
2
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in shuffler_fm.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Miguel Guinada
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,121 @@
1
+ # ShufflerFM [![Build Status](https://secure.travis-ci.org/mguinada/shuffler_fm.png?branch=master)](http://travis-ci.org/mguinada/shuffler_fm) [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/mguinada/shuffler_fm)
2
+
3
+ [travis]: http://travis-ci.org/mguinada/shuffler_fm
4
+ [codeclimate]: https://codeclimate.com/github/mguinada/shuffler_fm
5
+
6
+ Ruby API wrapper for [shuffler.fm v1 API](http://developers.shuffler.fm/)
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'shuffler_fm'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install shuffler_fm
21
+
22
+ ## Usage
23
+
24
+ ### Create an API instance
25
+ ```ruby
26
+
27
+ require 'shuffler_fm'
28
+
29
+ # Get and API key from http://shuffler.fm/developers
30
+ api = ShufflerFM.api('YOUR-KEY')
31
+ => #<ShufflerFM::API:0x000000027fa2b8 @key="YOUR-KEY">
32
+ ```
33
+
34
+ ### Read track data
35
+ ```ruby
36
+
37
+ # list tracks
38
+ tracks = api.tracks
39
+ => [#<Hashie::Rash blog=#<Hashie::Rash about=\"\" channel_url=\"http://api.shuffler.fm/v1/channels/blog:963?api-key=YOUR-KEY\" genres=[\"indie\", \"folk\", \"singer-songwriter\"] id=963 images=[#<Hashie::Rash height=240 url=\"http://assets.shuffler.fm/feeds/963/argeheartedboy_large.jpg\" width=240>] permalink=\"largehearted-boy\" profiles=#<Hashie::Rash facebook=nil twitter=nil> ...
40
+
41
+ # list operations are paginated
42
+ tracks = api.tracks(page: 2)
43
+
44
+ # request a particular track
45
+ track = api.track(1134715)
46
+
47
+ track.blog.title
48
+ => "Cover Freak"
49
+
50
+ track.post.url
51
+ => "http://coverfreak.com/2012/09/23/satisfaction/"
52
+
53
+ track.metadata.title
54
+ => "Satisfaction"
55
+
56
+ track.metadata.artist.name
57
+ => "Bjork & PJ Harvey"
58
+ ```
59
+
60
+ ### Search for an artist
61
+ ```ruby
62
+ api.search_artists('radiohead').map(&:name)
63
+ => ["Radiohead", "Radiohead at Lollapalooza 2008", "REM & Radiohead", "Radiohead 6. Permanent Daylight live", "Radiohead @ Optimus Alive'12", "I Can't Take The Hurt (Johnny Cash vs Tegan and Sarah and Radiohead)"]
64
+ ```
65
+
66
+ ### Read a channel's activity stream
67
+ ```ruby
68
+
69
+ activity = []
70
+ api.genre_channels('punk', 'rock').each do |act|
71
+ activity << "#{act.verb.capitalize} on #{act.actor.title} refering music track #{act.object.metadata.title}"
72
+ end
73
+
74
+ activity
75
+ => ["Post on The KEXP Blog refering music track Sunshine/Pretty Girls (Live on KEXP)",
76
+ "Post on PropertyOfZack refering music track Always Summer (Live Video)",
77
+ "Post on Nialler9 Music Blog refering music track Honningbarna (2012)",
78
+ "Post on This Is Fake DIY refering music track Coffin Song", ...
79
+ ```
80
+
81
+ and more ...
82
+
83
+ ### Configuration
84
+ ```ruby
85
+
86
+ ShufflerFM.configure do |config|
87
+ config.connection_timeout = 1 #seconds
88
+ config.read_timeout = 5 #seconds
89
+ config.proxy = { uri: 'http://192.168.1.1:8080', user: 'user1', password: 'passwd'}
90
+ end
91
+
92
+ #or
93
+
94
+ api = ShufflerFM.api("your-api-key", connection_timeout: 1, read_timeout: 5, proxy: 'http://192.168.1.1:8080')
95
+ ```
96
+
97
+ ## Reference
98
+
99
+ [shuffler_fm reference](http://rdoc.info/github/mguinada/shuffler_fm)
100
+
101
+ ## Contributing
102
+
103
+ 1. Fork it
104
+ 2. Create your topic branch (`git checkout -b my-topic-branch`)
105
+ 3. Add/change specs for your unimplemented feature or bug fix
106
+ 4. Make sure specs fail by running `bundle exec rake spec`. If not return to step 3
107
+ 5. Hack it
108
+ 6. Make sure specs pass (`bundle exec rake spec`). If not return to step 5
109
+ 7. Edit the documentation so it is coherent with your feature or fix. Run `bundle exec rake yard` to review
110
+ 8. Commit changes (`git commit -am 'Add some feature/fix'`) and push to the branch (`git push origin my-topic-branch`)
111
+ 9. Submit a pull request for your branch.
112
+
113
+ ## Influence
114
+
115
+ This API wrapper design is strongly influenced by the [Ocktokit gem](https://github.com/pengwynn/octokit)
116
+
117
+ ## Copyright
118
+ Copyright (c) 2012 Miguel Guinada
119
+ [LICENSE][] for details.
120
+
121
+ [license]: https://github.com/mguinada/shuffler_fm/blob/master/LICENSE
data/Rakefile ADDED
@@ -0,0 +1,37 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'yard'
4
+
5
+ task :test => :spec
6
+ task :default => :spec
7
+
8
+ RSpec::Core::RakeTask.new do |task|
9
+ task.rspec_opts = ["-c", "-f documentation", "-r ./spec/helper.rb"]
10
+ task.pattern = 'spec/**/*_spec.rb'
11
+ end
12
+
13
+ desc "Open an interactive session preloaded with this gem's code"
14
+ task :console do
15
+ if gem_available?("pry")
16
+ sh "pry -I lib -r shuffler_fm.rb"
17
+ else
18
+ sh "irb -rubygems -I lib -r shuffler_fm.rb"
19
+ end
20
+ end
21
+
22
+ desc "Generate documentation"
23
+ YARD::Rake::YardocTask.new do |t|
24
+ t.files = ['lib/**/*.rb']
25
+ t.options = ['--no-private', '--protected', '--markup', 'markdown']
26
+ end
27
+
28
+ #
29
+ # Determins if a gem is available at the current runtime
30
+ #
31
+ def gem_available?(name)
32
+ Gem::Specification.find_by_name(name)
33
+ rescue Gem::LoadError
34
+ false
35
+ rescue
36
+ Gem.available?(name) #for backwards compatibility
37
+ end
@@ -0,0 +1,53 @@
1
+ module ShufflerFM
2
+ class API
3
+ # Shuffler.fm API operations over artists
4
+ module Artists
5
+ # Requests a list of artists
6
+ #
7
+ # @param [Hash] options
8
+ # @option options [Integer] :page The page to request on paginated operation responses
9
+ #
10
+ # @return [Array] a list of artists
11
+ #
12
+ def artists(options = {})
13
+ get("/artists", :page => page(options))
14
+ end
15
+
16
+ # Requests a particular artist
17
+ #
18
+ # @param [Integer] id The artist id
19
+ #
20
+ # @return [Artist] the requested artist or nil if not found
21
+ #
22
+ def artist(id)
23
+ get("/artists/#{Integer(id)}")
24
+ rescue ShufflerFM::NotFound
25
+ nil
26
+ end
27
+
28
+ # Requests an artist's top blogs
29
+ #
30
+ # @param [Integer] id the artist id
31
+ # @param [Hash] options
32
+ # @option options [Integer] :page The page to request on paginated operation responses
33
+ #
34
+ # @return [Array] an array of results
35
+ #
36
+ def artist_blogs(id, options= {})
37
+ get("artists/#{Integer(id)}/blogs", :page => page(options))
38
+ end
39
+
40
+ # Search artists
41
+ #
42
+ # @param [String] q your query
43
+ # @param [Hash] options
44
+ # @option options [Integer] :page The page to request on paginated operation responses
45
+ #
46
+ # @return [Array] an array of results
47
+ #
48
+ def search_artists(q, options = {})
49
+ get("/artists?q=#{String(q)}", :page => page(options))
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,52 @@
1
+ module ShufflerFM
2
+ class API
3
+ # Shuffler.fm API operations over blogs
4
+ module Blogs
5
+ # Requests a list of blogs
6
+ #
7
+ # @param [Hash] options
8
+ # @option options [Integer] :page The page to request on paginated operation responses
9
+ #
10
+ # @return [Array] a list of blogs
11
+ #
12
+ def blogs(options = {})
13
+ get("/blogs", :page => page(options))
14
+ end
15
+
16
+ # Requests a list of featured blogs
17
+ #
18
+ # @param [Hash] options
19
+ # @option options [Integer] :page The page to request on paginated operation responses
20
+ #
21
+ # @return [Array] a list of featured blogs
22
+ #
23
+ def featured_blogs(options = {})
24
+ get("/blogs", :page => page(options), :filter => 'featured')
25
+ end
26
+
27
+ # Requests a particular blog
28
+ #
29
+ # @param [Integer] id The blog id
30
+ #
31
+ # @return [Blog] the requested blog or nil if not found
32
+ #
33
+ def blog(id)
34
+ get("/blogs/#{Integer(id)}")
35
+ rescue ShufflerFM::NotFound
36
+ nil
37
+ end
38
+
39
+ # Search blogs
40
+ #
41
+ # @param [String] q your query
42
+ # @param [Hash] options
43
+ # @option options [Integer] :page The page to request on paginated operation responses
44
+ #
45
+ # @return [Array] an array of results
46
+ #
47
+ def search_blogs(q, options = {})
48
+ get("/blogs?q=#{String(q)}", :page => page(options))
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,88 @@
1
+ module ShufflerFM
2
+ class API
3
+ # Shuffler.fm API operations over channels
4
+ module Channels
5
+ # Reads the media channels activity stream
6
+ #
7
+ # @param [String] key The channel key.
8
+ # Can be on of the following: mp3, youtube, vimeo, soundcloud or officialfm
9
+ # @param [Hash] options
10
+ # @option options [Integer] :page The page to request on paginated operation responses
11
+ #
12
+ # @return [Array] an array with the channel's activity stream
13
+ #
14
+ # @example
15
+ # api.media_channels('youtube', page: 2)
16
+ #
17
+ def media_channels(key, options = {})
18
+ channel(:media, key, options)
19
+ end
20
+
21
+ # Reads the blog channels activity stream
22
+ #
23
+ # @param [String] key The channel key.
24
+ # @param [Hash] options
25
+ # @option options [Integer] :page The page to request on paginated operation responses
26
+ #
27
+ # @return [Array] an array with the channel's activity stream
28
+ #
29
+ # @example
30
+ # api.blog_channels(21)
31
+ #
32
+ def blog_channels(key, options = {})
33
+ channel(:blog, key, options)
34
+ end
35
+
36
+ # Reads the artist channels activity stream
37
+ #
38
+ # @param key The channel key.
39
+ # @param [Hash] options
40
+ # @option options [Integer] :page The page to request on paginated operation responses
41
+ #
42
+ # @return [Array] an array with the channel's activity stream
43
+ #
44
+ # @example
45
+ # api.artist_channels('Pixies', page: 1)
46
+ #
47
+ def artist_channels(key, options = {})
48
+ channel(:artist, key, options)
49
+ end
50
+
51
+ # Reads the genere channels activity stream.
52
+ #
53
+ # @param [Array] keys The channel keys.
54
+ #
55
+ # @return [Array] an array with the channel's activity stream
56
+ #
57
+ # @example
58
+ # api.genre_channels('rock')
59
+ # api.genre_channels('punk', 'rock', page: 2)
60
+ #
61
+ def genre_channels(*keys)
62
+ channel(:genre, *keys)
63
+ end
64
+
65
+ private
66
+ def channel(*args)
67
+ key, query, opts = process_args(args)
68
+ get((key == :genre ? "channels/" : "channels/#{key}:") << "#{String(query.join('+'))}", :page => page(opts))
69
+ rescue ShufflerFM::NotFound
70
+ []
71
+ end
72
+
73
+ def process_args(args)
74
+ channels = %w(genre media blog artist)
75
+
76
+ if !channels.include?(args.first.to_s)
77
+ raise ArgumentError, "channel key must be one of: #{channels.join(', ')} but is #{args.first}"
78
+ end
79
+
80
+ if (query = Array(args[1..-1])).nil?
81
+ raise ArgumentError, "query value(s) must be provided"
82
+ end
83
+
84
+ return args.first.to_sym, query, query.last.is_a?(Hash) ? query.pop : {}
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,28 @@
1
+ module ShufflerFM
2
+ class API
3
+ # Shuffler.fm API operations over charts
4
+ module Charts
5
+ # Lists popular tracks charts
6
+ #
7
+ # @param [Hash] options
8
+ # @option options [Integer] :page The page to request on paginated operation responses
9
+ #
10
+ # @return [Array] a list of tracks merged with chart metadata
11
+ #
12
+ def popular_charts(options = {})
13
+ get("/charts/popular", :page => page(options))
14
+ end
15
+
16
+ # Lists tracks that were recently added to the popular list
17
+ #
18
+ # @param [Hash] options
19
+ # @option options [Integer] :page The page to request on paginated operation responses
20
+ #
21
+ # @return [Array] a list of tracks merged with chart metadata
22
+ #
23
+ def popular_charts_newest(options = {})
24
+ get("/charts/new", :page => page(options))
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ module ShufflerFM
2
+ class API
3
+ module Genres
4
+ # Requests a list of genres
5
+ #
6
+ # @param [Hash] options
7
+ # @option options [Integer] :page The page to request on paginated operation responses
8
+ #
9
+ # @return [Array] a list of genres
10
+ #
11
+ def genres(options = {})
12
+ get("/genres", :page => page(options))
13
+ end
14
+
15
+ # Requests a particular genre
16
+ #
17
+ # @param [Integer] id The genre id
18
+ #
19
+ # @return [Genre] the requested genre or nil if not found
20
+ #
21
+ def genre(id, options = {})
22
+ get("/genres/#{Integer(id)}", options)
23
+ rescue ShufflerFM::NotFound
24
+ nil
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,33 @@
1
+ module ShufflerFM
2
+ class API
3
+ # Shuffler.fm API operations over tracks
4
+ module Tracks
5
+ # Requests a list of tracks
6
+ #
7
+ # @param [Hash] options
8
+ # @option options [Integer] :page The page to request on paginated operation responses
9
+ #
10
+ # @return [Array] a list of tracks
11
+ #
12
+ # @example
13
+ # tracks = api.tracks #first page
14
+ # #...
15
+ # tracks = api.tracks(page: 2)
16
+ #
17
+ def tracks(options = {})
18
+ get("/tracks", :page => page(options))
19
+ end
20
+
21
+ # Requests a particular track
22
+ #
23
+ # @param [Integer] id The track id
24
+ # @return [Track] the requested track or nil if not found
25
+ #
26
+ def track(id)
27
+ get("/tracks/#{Integer(id)}")
28
+ rescue ShufflerFM::NotFound
29
+ nil
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,54 @@
1
+ require 'shuffler_fm/http'
2
+ require 'shuffler_fm/request'
3
+ require 'shuffler_fm/errors'
4
+
5
+ require 'shuffler_fm/api/blogs'
6
+ require 'shuffler_fm/api/tracks'
7
+ require 'shuffler_fm/api/artists'
8
+ require 'shuffler_fm/api/channels'
9
+ require 'shuffler_fm/api/charts'
10
+ require 'shuffler_fm/api/genres'
11
+
12
+ module ShufflerFM
13
+ class API
14
+ @base_uri = 'http://api.shuffler.fm/'
15
+ @version = 'v1'
16
+
17
+ include ShufflerFM::HTTP
18
+ include ShufflerFM::Request
19
+
20
+ include ShufflerFM::API::Blogs
21
+ include ShufflerFM::API::Tracks
22
+ include ShufflerFM::API::Artists
23
+ include ShufflerFM::API::Channels
24
+ include ShufflerFM::API::Charts
25
+ include ShufflerFM::API::Genres
26
+
27
+ class << self
28
+ attr_reader :base_uri, :version
29
+ end
30
+
31
+ # @!attribute [rw] key
32
+ # The API key
33
+ #
34
+ attr_reader :key
35
+
36
+ # Creates an API instance
37
+ #
38
+ # @param [String] key An api key provided by http://shuffler.fm
39
+ #
40
+ # @example get an API instance
41
+ # api = ShufflerFM::API.new("your-api-key")
42
+ # api.tracks # gets 1st page of the track list
43
+ #
44
+ def initialize(key)
45
+ raise ArgumentError, 'An API key must be provided' if key.nil?
46
+ @key = key
47
+ end
48
+
49
+ private
50
+ def page(options)
51
+ Integer(options.fetch(:page) { 1 })
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,44 @@
1
+ require 'hashie'
2
+
3
+ module ShufflerFM
4
+ # Configuration descriptor
5
+ class Configuration < Hashie::Dash
6
+ # @!attribute [rw] connection_timeout
7
+ # The connection timeout in seconds. Defaults to 2.
8
+ #
9
+ property :connection_timeout, :required => true, :default => 2
10
+ # @!attribute [rw] read_timeout
11
+ # The open/read timeout in seconds. Defaults to 5.
12
+ #
13
+ property :read_timeout, :required => true, :default => 5
14
+ # @!attribute [rw] proxy
15
+ # The proxy. Is unset by default.
16
+ #
17
+ # @example
18
+ # ShufflerFM.configure do |cfg|
19
+ # cfg.proxy = 'http://192.168.1.1:8080'
20
+ # end
21
+ #
22
+ # #or with authentication
23
+ #
24
+ # ShufflerFM.configure do |cfg|
25
+ # cfg.proxy = { uri: 'http://192.168.1.1:8080',
26
+ # user: 'user',
27
+ # password: 'passwd' }
28
+ # end
29
+ #
30
+ property :proxy, :default => nil
31
+
32
+ def initialize(cfg = {})
33
+ super(cfg)
34
+ end
35
+
36
+ # The current configuration as an hash
37
+ #
38
+ # @return [Hash]
39
+ #
40
+ def values
41
+ to_hash(:symbolize_keys => true)
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,37 @@
1
+ module ShufflerFM
2
+ # Root error class
3
+ class Error < StandardError; end
4
+
5
+ # Raised on the advent of a 400 HTTP status code
6
+ class BadRequest < Error; end
7
+
8
+ # Raised on the advent of a 401 HTTP status code
9
+ class Unauthorized < Error; end
10
+
11
+ # Raised on the advent of a 403 HTTP status code
12
+ class Forbidden < Error; end
13
+
14
+ # Raised on the advent of a 404 HTTP status code
15
+ class NotFound < Error; end
16
+
17
+ # Raised on the advent of a 406 HTTP status code
18
+ class NotAcceptable < Error; end
19
+
20
+ # Raised on the advent of a 422 HTTP status code
21
+ class UnprocessableEntity < Error; end
22
+
23
+ # Raised on the advent of a 429 HTTP status code
24
+ class TooManyRequests < Error; end
25
+
26
+ # Raised on the advent of a 500 HTTP status code
27
+ class InternalServerError < Error; end
28
+
29
+ # Raised on the advent of a 501 HTTP status code
30
+ class NotImplemented < Error; end
31
+
32
+ # Raised on the advent of a 502 HTTP status code
33
+ class BadGateway < Error; end
34
+
35
+ # Raised on the advent of a 503 HTTP status code
36
+ class ServiceUnavailable < Error; end
37
+ end
@@ -0,0 +1,25 @@
1
+ require 'faraday'
2
+ require 'faraday_middleware'
3
+ require 'shuffler_fm/middleware/error_handler'
4
+
5
+ module ShufflerFM
6
+ # @private
7
+ module HTTP
8
+ private
9
+ def connection
10
+ options = {:url => ShufflerFM::API.base_uri,
11
+ :params => {'api-key' => key}}.merge(ShufflerFM.configuration.values)
12
+
13
+ Faraday.new(options) do |builder|
14
+ builder.use FaradayMiddleware::Rashify
15
+ builder.use FaradayMiddleware::ParseJson
16
+
17
+ builder.use ShufflerFM::Middleware::ErrorHandler
18
+
19
+ builder.adapter Faraday.default_adapter
20
+ end
21
+ end
22
+
23
+ alias :http_connection :connection
24
+ end
25
+ end