Skip to content
This repository was archived by the owner on Feb 27, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
source "http://rubygems.org"
source 'http://rubygems.org'

gemspec
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
iTunes [![Build Status](https://secure.travis-ci.org/dewski/itunes.png)](http://travis-ci.org/dewski/itunes)
Tunes [![Build Status](https://secure.travis-ci.org/dewski/itunes.png)](http://travis-ci.org/dewski/itunes)
======

A Ruby wrapper around the iTunes API that lets you search for any sort of data that is available on the iTunes store.
Expand Down Expand Up @@ -54,13 +54,13 @@ Available Methods
* software
* all

Using the iTunes gem
Using the Tunes gem
--------------------

require 'itunes'
require 'tunes'

>> itunes = ITunes::Client.new
>> songs = itunes.music('green day she')
>> tunes = Tunes::Client.new
>> songs = tunes.music('green day she')
=> <#Hashie::Rash result_count=15 results=[...]>
>> songs.results.each do |song|
>> puts "#{song.track_name} - #{song.artist_name} (#{song.collection_name})"
Expand All @@ -73,12 +73,12 @@ Using the iTunes gem

Search directly from the class

>> iron_man = ITunes.movie('iron man 2')
>> iron_man = Tunes.movie('iron man 2')
=> <#Hashie::Rash result_count=1 results=[...]>

Limit the results:

>> foo_fighters = ITunes.music('foo fighters everlong', :limit => 1)
>> foo_fighters = Tunes.music('foo fighters everlong', :limit => 1)
=> <#Hashie::Rash result_count=1 results=[<#Hashie::Rash ...>]>

What is Hashie::Rash?
Expand Down
8 changes: 4 additions & 4 deletions itunes.gemspec
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path('../lib', __FILE__)
require 'itunes/version'
require 'tunes/version'

Gem::Specification.new do |s|
s.name = 'itunes'
s.version = ITunes::VERSION
s.name = 'tunes'
s.version = Tunes::VERSION
s.platform = Gem::Platform::RUBY
s.authors = ['Garrett Bjerkhoel', 'Steve Agalloco']
s.email = %q{me@garrettbjerkhoel.com}
s.homepage = %q{http://github.com/dewski/itunes}
s.homepage = %q{http://github.com/dewski/tunes}
s.summary = %q{iTunes API}

s.rubyforge_project = 'itunes'
Expand Down
33 changes: 2 additions & 31 deletions lib/itunes.rb
Original file line number Diff line number Diff line change
@@ -1,31 +1,2 @@
require 'faraday_middleware'
require 'itunes/configuration'
require 'itunes/client'

module ITunes
extend Configuration

# Alias for ITunes::Client.new
#
# @return [ITunes::Client]
def self.client(options={})
ITunes::Client.new(options)
end

# Alias for ITunes::Client.new
#
# @return [ITunes::Client]
def self.new(options={})
ITunes::Client.new(options)
end

# Delegate to ITunes::Client
def self.method_missing(method, *args, &block)
return super unless new.respond_to?(method)
new.send(method, *args, &block)
end

def self.respond_to?(method, include_private = false)
new.respond_to?(method, include_private) || super(method, include_private)
end
end
require 'tunes'
ITunes = Tunes
36 changes: 0 additions & 36 deletions lib/itunes/request.rb

This file was deleted.

31 changes: 31 additions & 0 deletions lib/tunes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require 'faraday_middleware'
require 'tunes/configuration'
require 'tunes/client'

module Tunes
extend Configuration

# Alias for Tunes::Client.new
#
# @return [Tunes::Client]
def self.client(options={})
Client.new options
end

# Alias for Tunes::Client.new
#
# @return [Tunes::Client]
def self.new(options={})
Client.new options
end

# Delegate to Tunes::Client
def self.method_missing(method, *args, &block)
return super unless new.respond_to?(method)
new.send(method, *args, &block)
end

def self.respond_to?(method, include_private = false)
new.respond_to?(method, include_private) || super(method, include_private)
end
end
4 changes: 2 additions & 2 deletions lib/itunes/client.rb → lib/tunes/client.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
require File.expand_path('../request', __FILE__)

module ITunes
module Tunes
class Client

# @private
attr_accessor *Configuration::VALID_OPTIONS_KEYS

# Creates a new Client
def initialize(options={})
options = ITunes.options.merge(options)
options = Tunes.options.merge(options)
Configuration::VALID_OPTIONS_KEYS.each do |key|
send("#{key}=", options[key])
end
Expand Down
2 changes: 1 addition & 1 deletion lib/itunes/client/lookup.rb → lib/tunes/client/lookup.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module ITunes
module Tunes
module Lookup

ID_TYPES = { :amg_artist => 'amgArtistId', :id => 'id', :amg_album => 'amgAlbumId', :upc => 'upc' }
Expand Down
2 changes: 1 addition & 1 deletion lib/itunes/client/search.rb → lib/tunes/client/search.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module ITunes
module Tunes
module Search

# Performs a music search
Expand Down
4 changes: 2 additions & 2 deletions lib/itunes/configuration.rb → lib/tunes/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'faraday'
require File.expand_path('../version', __FILE__)

module ITunes
module Tunes
# Defines constants and methods related to configuration
module Configuration

Expand All @@ -17,7 +17,7 @@ module Configuration
DEFAULT_ENDPOINT = 'http://ax.itunes.apple.com'.freeze

# The user agent that will be sent to the API endpoint if none is set
DEFAULT_USER_AGENT = "ITunes Ruby Gem #{ITunes::VERSION}".freeze
DEFAULT_USER_AGENT = "ITunes Ruby Gem #{Tunes::VERSION}".freeze

# The default number of results to return from the API
#
Expand Down
35 changes: 35 additions & 0 deletions lib/tunes/request.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module Tunes
module Request
REQUEST_OPTIONS = {
:timeout => 5,
:open_timeout => 5
}

# @private
private

# Perform an HTTP GET request
def request(request_type, params)
url = '/WebObjects/MZStoreServices.woa/wa/ws' + request_type

response = connection.get do |req|
req.url url, params
req.options = REQUEST_OPTIONS
end
response.body
end

def connection
options = {
:headers => {'Accept' => 'application/json', 'User-Agent' => user_agent},
:url => api_endpoint,
}

Faraday.new(options) do |builder|
builder.use Faraday::Response::Rashify
builder.use Faraday::Response::ParseJson
builder.adapter(adapter)
end
end
end
end
2 changes: 1 addition & 1 deletion lib/itunes/version.rb → lib/tunes/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module ITunes
module Tunes
VERSION = '0.5.5'
end
Loading