prx_client 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in prx_client.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,5 @@
1
+ module PRX
2
+ module Client
3
+ VERSION = "0.0.2"
4
+ end
5
+ end
data/lib/prx/client.rb ADDED
@@ -0,0 +1,64 @@
1
+ require 'prx/client/version'
2
+ require 'prx/model'
3
+
4
+ module PRX
5
+ module Client
6
+
7
+ class << self
8
+
9
+ include PRX::Model
10
+
11
+ attr_accessor :key, :secret, :scheme, :host, :port, :version, :token, :client_options, :access_token_options
12
+
13
+ # get information about the current user
14
+ def me
15
+ access_token.get('/me', default_options)
16
+ end
17
+
18
+ def piece_create(piece)
19
+ client_options[:multipart] = true
20
+ access_token.post(create_url('pieces'), :body=>{:piece=>piece.as_json}, 'Content-Type' => 'application/json')
21
+ # access_token.post(create_url('pieces'), :body=>{:test=>{:nested=>piece.audio_versions[0].audio_files[0].file}})
22
+ # access_token.post(create_url('pieces'), :body=>{:test=>[piece.audio_versions[0].audio_files[0].file]})
23
+ end
24
+
25
+ def client_options; @client_options ||= {}; end
26
+ def access_token_options; @access_token_options ||= {}; end
27
+
28
+ protected
29
+
30
+ def create_url(path)
31
+ "/api/#{version}/#{path}"
32
+ end
33
+
34
+ def client
35
+ options = client_options.clone
36
+ options[:site] = site unless options.has_key?(:site)
37
+ OAuth2::Client.new(key, secret, {:site=>site}) do |b|
38
+
39
+ b.request :multipart # if options[:multipart]
40
+ b.request :url_encoded
41
+ b.request :json
42
+
43
+ # b.response :logger
44
+
45
+ b.adapter :net_http
46
+ end
47
+ end
48
+
49
+ def access_token
50
+ OAuth2::AccessToken.new(client, token, access_token_options.clone)
51
+ end
52
+
53
+ def site
54
+ "#{scheme || 'http'}://#{host}:#{port}"
55
+ end
56
+
57
+ def default_options
58
+ {'Accept' => 'application/json'}
59
+ end
60
+
61
+ end
62
+
63
+ end
64
+ end
@@ -0,0 +1,21 @@
1
+ require 'prx/representer/account_representer'
2
+
3
+ module PRX
4
+ module Model
5
+ class Account < PRX::Model::Base
6
+
7
+ include PRX::Representer::AccountRepresenter
8
+
9
+ # attr_accessor :name
10
+ # attr_accessor :type
11
+ #
12
+ # # relationships
13
+ # attr_accessor :networks
14
+ #
15
+ # def initialize(*args)
16
+ # super
17
+ # end
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,57 @@
1
+ require 'prx/representer/audio_file_representer'
2
+
3
+ module PRX
4
+ module Model
5
+ class AudioFile < PRX::Model::Base
6
+
7
+ include PRX::Representer::AudioFileRepresenter
8
+
9
+ def file=(f)
10
+ super
11
+ prepare_file_upload if f
12
+ self.file
13
+ end
14
+
15
+ def prepare_file_upload
16
+ if self.file.is_a?(String)
17
+ uri = URI.parse(@file)
18
+ if uri.scheme.blank? || (uri.scheme == 'file')
19
+ self.file = Faraday::UploadIO.new(uri.path, self.content_type)
20
+ end
21
+ end
22
+ end
23
+
24
+ def initialize(*args)
25
+ self.content_type = 'audio/mpeg'
26
+ super
27
+ self
28
+ end
29
+
30
+ # attr_accessor :label, :file, :content_type, :size, :status
31
+
32
+
33
+ #
34
+ # def file=(f)
35
+ # @file = f
36
+ # check_upload_file
37
+ # end
38
+ #
39
+ # def content_type=(m)
40
+ # raise "content_type cannot be blank" if m.blank?
41
+ # @content_type = m
42
+ # end
43
+ #
44
+ # def check_upload_file
45
+ # if @file.is_a?(String)
46
+ # uri = URI.parse(@file)
47
+ # if uri.scheme.blank? || (uri.scheme == 'file')
48
+ # @file = Faraday::UploadIO.new(uri.path, self.content_type)
49
+ # end
50
+ # end
51
+ # @file
52
+ # end
53
+
54
+
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,31 @@
1
+ require 'prx/representer/audio_version_representer'
2
+
3
+ module PRX
4
+ module Model
5
+ class AudioVersion < PRX::Model::Base
6
+
7
+ include PRX::Representer::AudioVersionRepresenter
8
+
9
+ def initialize(*args)
10
+ super
11
+ self.audio_files ||= []
12
+ end
13
+
14
+ # attr_accessor :label
15
+ #
16
+ # # relationships
17
+ # attr_accessor :audio_files
18
+ #
19
+ # def initialize(*args)
20
+ # super
21
+ # @audio_files ||= []
22
+ # @json_options = {:include=>['audio_files']}
23
+ # end
24
+ #
25
+ # def audio_files=(afs)
26
+ # @promos = Array(afs).collect{|af| AudioFile.new(af) unless af.is_a?(AudioFile)}
27
+ # end
28
+ #
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,45 @@
1
+ require 'roar/representer'
2
+ require 'roar/representer/json'
3
+
4
+ module PRX
5
+ module Model
6
+ class Base
7
+
8
+ include Roar::Representer::JSON
9
+
10
+ # attr_accessor :id, :link
11
+
12
+ def initialize(*args)
13
+ return unless args
14
+ if args[0].is_a?(Hash)
15
+ args[0].each{|k,v| self.send("#{k.to_s}=", v)}
16
+ end
17
+ end
18
+
19
+ # def as_json_with_class_name(options={})
20
+ # options = options.merge(@json_options) if @json_options
21
+ # hash = as_json_without_class_name(options)
22
+ # hash.delete('json_options')
23
+ #
24
+ # Array(options[:include]).each do |attribute|
25
+ # child_options = {:include_root=>false}
26
+ # value = self.send(attribute)
27
+ # hash[attribute.to_s] = value.is_a?(Enumerable) ? value.map {|r| r.as_json(child_options)} : value.as_json(child_options)
28
+ # end
29
+ #
30
+ # if options.has_key?(:include_root) && !options[:include_root]
31
+ # hash
32
+ # else
33
+ # {self.class.name.demodulize.underscore.to_sym => hash}
34
+ # end
35
+ #
36
+ # end
37
+ # alias_method_chain :as_json, :class_name
38
+ #
39
+ # def to_request(options={})
40
+ # as_json(options)
41
+ # end
42
+
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,21 @@
1
+ require 'prx/representer/network_representer'
2
+
3
+ module PRX
4
+ module Model
5
+ class Network < PRX::Model::Base
6
+
7
+ include PRX::Representer::AccountRepresenter
8
+
9
+ # attr_accessor :name
10
+ # attr_accessor :type
11
+ #
12
+ # # relationships
13
+ # attr_accessor :networks
14
+ #
15
+ # def initialize(*args)
16
+ # super
17
+ # end
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,62 @@
1
+ require 'prx/representer/piece_representer'
2
+
3
+ module PRX
4
+ module Model
5
+ class Piece < PRX::Model::Base
6
+
7
+ include PRX::Representer::PieceRepresenter
8
+
9
+ def initialize(*args)
10
+ super
11
+ self.audio_versions ||= []
12
+ self.networks ||= []
13
+ end
14
+
15
+ def add_audio(audio={})
16
+ if self.audio_versions.size < 1
17
+ self.audio_versions << AudioVersion.new(:label=>'Piece Audio')
18
+ end
19
+ self.audio_versions[0].audio_files << AudioFile.new(audio)
20
+ end
21
+
22
+ # attr_accessor :title
23
+ # attr_accessor :short_description
24
+ # attr_accessor :description
25
+ # attr_accessor :published_at
26
+ # attr_accessor :created_at
27
+ # attr_accessor :produced_on
28
+ # attr_accessor :episode_number
29
+ # attr_accessor :length
30
+ #
31
+ # # relationships
32
+ # attr_accessor :audio_versions
33
+ # attr_accessor :promos
34
+ # attr_accessor :account
35
+ # attr_accessor :series
36
+ #
37
+ # def initialize(*args)
38
+ # super
39
+ # @promos ||= []
40
+ # @audio_versions ||= []
41
+ # @json_options = {:include=>['audio_versions', 'promos']}
42
+ # end
43
+ #
44
+ # def audio_versions=(avs)
45
+ # @audio_versions = Array(avs).collect{|av| AudioVersion.new(av) unless av.is_a?(AudioVersion)}
46
+ # end
47
+ #
48
+ # def promos=(ps)
49
+ # @promos = Array(ps).collect{|p| AudioFile.new(p) unless p.is_a?(AudioFile)}
50
+ # end
51
+ #
52
+ # # add an audio asset as a hash
53
+ # def add_audio(audio={})
54
+ # if audio_versions.size < 1
55
+ # audio_versions << AudioVersion.new(:label=>'Piece Audio')
56
+ # end
57
+ # audio_versions[0].audio_files << AudioFile.new(audio)
58
+ # end
59
+
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,11 @@
1
+ require 'prx/representer/series_representer'
2
+
3
+ module PRX
4
+ module Model
5
+ class Series < PRX::Model::Base
6
+
7
+ include PRX::Representer::SeriesRepresenter
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,17 @@
1
+ require 'prx/representer/user_representer'
2
+
3
+ module PRX
4
+ module Model
5
+ class User < PRX::Model::Base
6
+
7
+ include PRX::Representer::UserRepresenter
8
+
9
+ # attr_accessor :login, :email, :first_name, :last_name
10
+ #
11
+ # def initialize(*args)
12
+ # super
13
+ # end
14
+
15
+ end
16
+ end
17
+ end
data/lib/prx/model.rb ADDED
@@ -0,0 +1,8 @@
1
+ require "prx/model/base"
2
+ require "prx/model/account"
3
+ require "prx/model/audio_file"
4
+ require "prx/model/audio_version"
5
+ require "prx/model/network"
6
+ require "prx/model/series"
7
+ require "prx/model/user"
8
+ require "prx/model/piece"
@@ -0,0 +1,18 @@
1
+ require 'roar/representer'
2
+ require 'roar/representer/json'
3
+ require 'roar/representer/feature/hypermedia'
4
+
5
+ module PRX
6
+ module Representer
7
+ module AccountRepresenter
8
+ include Roar::Representer::JSON
9
+ include Roar::Representer::Feature::Hypermedia
10
+
11
+ property :id
12
+ property :name
13
+ property :path
14
+ property :type
15
+
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,21 @@
1
+ require 'roar/representer'
2
+ require 'roar/representer/json'
3
+ require 'roar/representer/feature/hypermedia'
4
+
5
+ module PRX
6
+ module Representer
7
+ module AudioFileRepresenter
8
+ include Roar::Representer::JSON
9
+ include Roar::Representer::Feature::Hypermedia
10
+
11
+ property :id
12
+ property :label
13
+ property :file
14
+ property :content_type
15
+ property :size
16
+ property :status
17
+ property :length
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ require 'roar/representer'
2
+ require 'roar/representer/json'
3
+ require 'roar/representer/feature/hypermedia'
4
+ require 'prx/model'
5
+
6
+ module PRX
7
+ module Representer
8
+ module AudioVersionRepresenter
9
+ include Roar::Representer::JSON
10
+ include Roar::Representer::Feature::Hypermedia
11
+
12
+ property :id
13
+ property :label
14
+
15
+ collection :audio_files,
16
+ :class => PRX::Model::AudioFile,
17
+ :extend => PRX::Representer::AudioFileRepresenter
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,17 @@
1
+ require 'roar/representer'
2
+ require 'roar/representer/json'
3
+ require 'roar/representer/feature/hypermedia'
4
+
5
+ module PRX
6
+ module Representer
7
+ module NetworkRepresenter
8
+ include Roar::Representer::JSON
9
+ include Roar::Representer::Feature::Hypermedia
10
+
11
+ property :id
12
+ property :name
13
+ property :path
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,43 @@
1
+ require 'roar/representer'
2
+ require 'roar/representer/json'
3
+ require 'roar/representer/feature/hypermedia'
4
+ require 'prx/model'
5
+
6
+ module PRX
7
+ module Representer
8
+ module PieceRepresenter
9
+ include Roar::Representer::JSON
10
+ include Roar::Representer::Feature::Hypermedia
11
+
12
+ property :id
13
+ property :title
14
+ property :short_description
15
+ property :description
16
+ property :account_id
17
+ property :published_at
18
+ property :created_at
19
+ property :produced_on
20
+ property :episode_number
21
+ property :length
22
+
23
+ property :promos,
24
+ :class => PRX::Model::AudioVersion,
25
+ :extend => PRX::Representer::AudioVersionRepresenter
26
+
27
+ property :account, :class => PRX::Model::Account, :extend => PRX::Representer::AccountRepresenter
28
+
29
+ property :series,
30
+ :class => PRX::Model::Series,
31
+ :extend => PRX::Representer::SeriesRepresenter
32
+
33
+ collection :audio_versions,
34
+ :class => PRX::Model::AudioVersion,
35
+ :extend => PRX::Representer::AudioVersionRepresenter
36
+
37
+ collection :networks,
38
+ :class => PRX::Model::Network,
39
+ :extend => PRX::Representer::NetworkRepresenter
40
+
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,16 @@
1
+ require 'roar/representer'
2
+ require 'roar/representer/json'
3
+ require 'roar/representer/feature/hypermedia'
4
+
5
+ module PRX
6
+ module Representer
7
+ module SeriesRepresenter
8
+ include Roar::Representer::JSON
9
+ include Roar::Representer::Feature::Hypermedia
10
+
11
+ property :id
12
+ property :title
13
+
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,19 @@
1
+ require 'roar/representer'
2
+ require 'roar/representer/json'
3
+ require 'roar/representer/feature/hypermedia'
4
+
5
+ module PRX
6
+ module Representer
7
+ module UserRepresenter
8
+ include Roar::Representer::JSON
9
+ include Roar::Representer::Feature::Hypermedia
10
+
11
+ property :id
12
+ property :login
13
+ property :email
14
+ property :first_name
15
+ property :last_name
16
+
17
+ end
18
+ end
19
+ end
data/lib/prx_client.rb ADDED
@@ -0,0 +1,14 @@
1
+ require 'i18n'
2
+ require 'oauth2'
3
+ require 'json'
4
+
5
+ require 'active_support'
6
+ require 'active_support/core_ext'
7
+ require 'active_support/core_ext/module'
8
+ require 'active_support/core_ext/module/aliasing'
9
+ require 'active_support/json/encoding'
10
+ require 'active_support/all'
11
+
12
+ require "prx/client"
13
+ require "prx/model"
14
+
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "prx/client/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "prx_client"
7
+ s.version = PRX::Client::VERSION
8
+ s.authors = ["Andrew Kuklewicz"]
9
+ s.email = ["andrew@prx.org"]
10
+ s.homepage = "http://labs.prx.org"
11
+ s.summary = %q{Client for PRX OAuth2 API (v2) }
12
+
13
+ s.files = `git ls-files`.split("\n")
14
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
+ s.require_paths = ["lib"]
17
+
18
+ # s.add_runtime_dependency "iconv"
19
+ s.add_runtime_dependency 'yajl-ruby'
20
+ s.add_runtime_dependency "i18n"
21
+ s.add_runtime_dependency "json"
22
+ s.add_runtime_dependency "activesupport"
23
+ s.add_runtime_dependency "oauth2"
24
+ s.add_runtime_dependency "roar"
25
+
26
+ # specify any dependencies here; for example:
27
+ s.add_development_dependency "rake"
28
+ s.add_development_dependency "test-unit"
29
+ s.add_development_dependency 'fakeweb'
30
+
31
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ require 'prx_client'
7
+
8
+ class Test::Unit::TestCase
9
+ end
@@ -0,0 +1,20 @@
1
+ load './helper.rb'
2
+ require 'prx/client'
3
+ require 'prx/model'
4
+ require 'net/http'
5
+
6
+ class PRX::TestAccount < Test::Unit::TestCase
7
+
8
+ def test_initialize
9
+ a = PRX::Model::Account.new(:name=>'n', :id=>1)
10
+ assert a.is_a?(PRX::Model::Account)
11
+ assert_equal a.name, 'n'
12
+ assert_equal a.id, 1
13
+ end
14
+
15
+ def test_to_hash
16
+ a = PRX::Model::Account.new(:name=>'n', :id=>1)
17
+ assert_equal a.to_hash, {"name"=>"n", "id"=>1}
18
+ end
19
+
20
+ end
@@ -0,0 +1,24 @@
1
+ load './helper.rb'
2
+ require 'prx/client'
3
+ require 'prx/model'
4
+ require 'net/http'
5
+
6
+ class PRX::TestAudioFile < Test::Unit::TestCase
7
+
8
+ def test_initialize
9
+ af = PRX::Model::AudioFile.new(:id=>1, :label=>'l', :size=>3000, :length=>30, :status=>'new', :content_type=>'audio/wav' )
10
+ assert af.is_a?(PRX::Model::AudioFile)
11
+ assert af.as_json === {"label"=>"l", "size"=>3000, "content_type"=>"audio/wav", "id"=>1, "length"=>30, "status"=>"new"}
12
+ end
13
+
14
+ def test_default_content_type
15
+ af = PRX::Model::AudioFile.new()
16
+ assert_equal af.content_type, 'audio/mpeg'
17
+ end
18
+
19
+ def test_prepare_upload
20
+ af = PRX::Model::AudioFile.new(:file=>'/Users/akuklewicz/test.mp2')
21
+ assert af.file.is_a?(Faraday::UploadIO)
22
+ end
23
+
24
+ end
@@ -0,0 +1,27 @@
1
+ load './helper.rb'
2
+ require 'prx/client'
3
+ require 'prx/model'
4
+ require 'net/http'
5
+
6
+ class PRX::TestAudioVersion < Test::Unit::TestCase
7
+
8
+ def test_initialize
9
+ af = PRX::Model::AudioVersion.new(:label=>'l')
10
+ assert af.is_a?(PRX::Model::AudioVersion)
11
+ assert_equal({"label"=>"l", "audio_files"=>[]}.to_json, af.to_json)
12
+ end
13
+
14
+ def test_initialize_with_audio_files
15
+ af = PRX::Model::AudioVersion.new(:label=>'l', :audio_files=>[PRX::Model::AudioFile.new(:label=>'af')])
16
+ assert af.is_a?(PRX::Model::AudioVersion)
17
+ assert_equal({"label"=>"l", "audio_files"=>[{"label"=>"af", "content_type"=>"audio/mpeg"}]}.to_json, af.to_json)
18
+ end
19
+
20
+ def test_initialize_with_json
21
+ json = {"label"=>"l", "audio_files"=>[{"label"=>"af"}]}.to_json
22
+ af = PRX::Model::AudioVersion.from_json(json)
23
+ assert af.is_a?(PRX::Model::AudioVersion)
24
+ assert af.audio_files.first.is_a?(PRX::Model::AudioFile)
25
+ end
26
+
27
+ end
@@ -0,0 +1,59 @@
1
+ load './helper.rb'
2
+ require 'prx/client'
3
+ require 'prx/model'
4
+ require 'net/http'
5
+ require 'fakeweb'
6
+
7
+ class PRX::TestClient < Test::Unit::TestCase
8
+
9
+ def setup
10
+ PRX::Client.key = 'bZG3A36fAVa9UTD3TlUN2L17Q2loTAN3G9tyOfVF'
11
+ PRX::Client.secret = 'rGrSNofeaJCbfDjJtYMFAQSfUIQhtr1vkNnaZQvf'
12
+ PRX::Client.host = "development.prx.org"
13
+ PRX::Client.port = 3001
14
+ PRX::Client.version = 'v2'
15
+ PRX::Client.token = 'Kq4FhSK3arQ7jZ9xhiVAbDKw30mvXv4C8sl2CzCV'
16
+
17
+ user = {
18
+ :uid => '1001',
19
+ :provider => 'PRX',
20
+ :info => {
21
+ :id => '1001',
22
+ :login => 'test_login',
23
+ :email => 'test@prx.org',
24
+ :first_name => 'first',
25
+ :last_name => 'last'
26
+ }
27
+ }
28
+
29
+ # FakeWeb.register_uri(:get, "http://development.prx.org:3001/me", :body=>user.to_json)
30
+ #
31
+ # FakeWeb.register_uri(:post, "http://development.prx.org:3001/api/v2/pieces", :body=>{}.to_json)
32
+
33
+ end
34
+
35
+ # def test_me
36
+ # response = PRX::Client.me
37
+ # puts response.parsed.inspect
38
+ # end
39
+
40
+ def test_piece_create_with_local_file
41
+ p = PRX::Model::Piece.new(:title=>'test title',
42
+ :short_description=>'test short description',
43
+ :description=>'test description',
44
+ :account=>PRX::Model::Account.new(:id=>8))
45
+
46
+ puts p.to_json.inspect
47
+ p.add_audio(:label=>'test', :file=>'/Users/akuklewicz/test.mp2', :content_type=>'audio/mpeg')
48
+ response = PRX::Client.piece_create(p)
49
+ puts response.parsed.inspect
50
+ end
51
+
52
+ # def test_piece_create_with_remote_url
53
+ # p = PRX::Model::Piece.new(:title=>'test title', :short_description=>'test short description', :description=>'test description', :account_id=>8)
54
+ # p.add_audio(:label=>'test', :file=>'s3://andrew-s3.prx.org/public/audio_files/118091/Baronowski.mp2', :size=>1)
55
+ # response = PRX::Client.piece_create(p)
56
+ # puts response.parsed.inspect
57
+ # end
58
+
59
+ end
@@ -0,0 +1,21 @@
1
+ load './helper.rb'
2
+ require 'prx/client'
3
+ require 'prx/model'
4
+ require 'net/http'
5
+
6
+ class PRX::TestNetwork < Test::Unit::TestCase
7
+
8
+ def test_initialize
9
+ a = PRX::Model::Network.new(:name=>'n', :id=>1, :path=>'p')
10
+ assert a.is_a?(PRX::Model::Network)
11
+ assert_equal a.name, 'n'
12
+ assert_equal a.id, 1
13
+ assert_equal a.path, 'p'
14
+ end
15
+
16
+ def test_to_hash
17
+ a = PRX::Model::Network.new(:name=>'n', :id=>1)
18
+ assert_equal a.to_hash, {"name"=>"n", "id"=>1}
19
+ end
20
+
21
+ end
@@ -0,0 +1,41 @@
1
+ load './helper.rb'
2
+ require 'prx/client'
3
+ require 'prx/model'
4
+ require 'net/http'
5
+
6
+ class PRX::TestPiece < Test::Unit::TestCase
7
+
8
+ def test_initialize
9
+ a = PRX::Model::Piece.new(:title=>'t', :id=>1)
10
+ assert a.is_a?(PRX::Model::Piece)
11
+ assert_equal a.title, 't'
12
+ assert_equal a.id, 1
13
+ end
14
+
15
+ def test_initialize_with_account_json
16
+ a = PRX::Model::Piece.from_json({:title=>'t', :id=>1, :account=>{:id=>2}}.to_json)
17
+ assert a.account.is_a?(PRX::Model::Account)
18
+ end
19
+
20
+ def test_initialize_with_account_object
21
+ a = PRX::Model::Piece.from_json({:title=>'t', :id=>1, :account=>PRX::Model::Account.new(:id=>2)})
22
+ assert a.account.is_a?(PRX::Model::Account)
23
+ end
24
+
25
+ def test_piece_create_with_local_file
26
+ p = PRX::Model::Piece.new(:title=>'test title')
27
+ p.add_audio(:label=>'test', :file=>'/Users/akuklewicz/test.mp2', :content_type=>'audio/mpeg')
28
+ af = p.audio_versions[0].audio_files[0]
29
+ assert af.is_a?(PRX::Model::AudioFile)
30
+ assert af.file.is_a?(Faraday::UploadIO)
31
+ end
32
+
33
+ def test_piece_create_with_remote_url
34
+ p = PRX::Model::Piece.new(:title=>'test title')
35
+ p.add_audio(:label=>'test', :file=>'s3://andrew-s3.prx.org/test/test_short_download.mp3')
36
+ af = p.audio_versions[0].audio_files[0]
37
+ assert af.is_a?(PRX::Model::AudioFile)
38
+ assert af.file.is_a?(String)
39
+ end
40
+
41
+ end
@@ -0,0 +1,20 @@
1
+ load './helper.rb'
2
+ require 'prx/client'
3
+ require 'prx/model'
4
+ require 'net/http'
5
+
6
+ class PRX::TestSeries < Test::Unit::TestCase
7
+
8
+ def test_initialize
9
+ s = PRX::Model::Series.new(:title=>'t', :id=>1)
10
+ assert s.is_a?(PRX::Model::Series)
11
+ assert_equal s.title, 't'
12
+ assert_equal s.id, 1
13
+ end
14
+
15
+ def test_to_hash
16
+ s = PRX::Model::Series.new(:title=>'t', :id=>1)
17
+ assert_equal s.to_hash, {"title"=>"t", "id"=>1}
18
+ end
19
+
20
+ end
data/test/test_user.rb ADDED
@@ -0,0 +1,20 @@
1
+ load './helper.rb'
2
+ require 'prx/client'
3
+ require 'prx/model'
4
+ require 'net/http'
5
+
6
+ class PRX::TestUser < Test::Unit::TestCase
7
+
8
+ def test_initialize
9
+ s = PRX::Model::User.new(:email=>'t', :id=>1)
10
+ assert s.is_a?(PRX::Model::User)
11
+ assert_equal s.email, 't'
12
+ assert_equal s.id, 1
13
+ end
14
+
15
+ def test_to_hash
16
+ s = PRX::Model::User.new(:email=>'t', :id=>1)
17
+ assert_equal s.to_hash, {"email"=>"t", "id"=>1}
18
+ end
19
+
20
+ end
metadata ADDED
@@ -0,0 +1,185 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: prx_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Andrew Kuklewicz
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-22 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: yajl-ruby
16
+ requirement: &2152944900 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2152944900
25
+ - !ruby/object:Gem::Dependency
26
+ name: i18n
27
+ requirement: &2152943600 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *2152943600
36
+ - !ruby/object:Gem::Dependency
37
+ name: json
38
+ requirement: &2152942660 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *2152942660
47
+ - !ruby/object:Gem::Dependency
48
+ name: activesupport
49
+ requirement: &2152941300 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *2152941300
58
+ - !ruby/object:Gem::Dependency
59
+ name: oauth2
60
+ requirement: &2152939900 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: *2152939900
69
+ - !ruby/object:Gem::Dependency
70
+ name: roar
71
+ requirement: &2152939040 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: *2152939040
80
+ - !ruby/object:Gem::Dependency
81
+ name: rake
82
+ requirement: &2152937740 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *2152937740
91
+ - !ruby/object:Gem::Dependency
92
+ name: test-unit
93
+ requirement: &2152936140 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *2152936140
102
+ - !ruby/object:Gem::Dependency
103
+ name: fakeweb
104
+ requirement: &2152935100 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: *2152935100
113
+ description:
114
+ email:
115
+ - andrew@prx.org
116
+ executables: []
117
+ extensions: []
118
+ extra_rdoc_files: []
119
+ files:
120
+ - .gitignore
121
+ - Gemfile
122
+ - Rakefile
123
+ - lib/prx/client.rb
124
+ - lib/prx/client/version.rb
125
+ - lib/prx/model.rb
126
+ - lib/prx/model/account.rb
127
+ - lib/prx/model/audio_file.rb
128
+ - lib/prx/model/audio_version.rb
129
+ - lib/prx/model/base.rb
130
+ - lib/prx/model/network.rb
131
+ - lib/prx/model/piece.rb
132
+ - lib/prx/model/series.rb
133
+ - lib/prx/model/user.rb
134
+ - lib/prx/representer/account_representer.rb
135
+ - lib/prx/representer/audio_file_representer.rb
136
+ - lib/prx/representer/audio_version_representer.rb
137
+ - lib/prx/representer/network_representer.rb
138
+ - lib/prx/representer/piece_representer.rb
139
+ - lib/prx/representer/series_representer.rb
140
+ - lib/prx/representer/user_representer.rb
141
+ - lib/prx_client.rb
142
+ - prx_client.gemspec
143
+ - test/helper.rb
144
+ - test/test_account.rb
145
+ - test/test_audio_file.rb
146
+ - test/test_audio_version.rb
147
+ - test/test_client.rb
148
+ - test/test_network.rb
149
+ - test/test_piece.rb
150
+ - test/test_series.rb
151
+ - test/test_user.rb
152
+ homepage: http://labs.prx.org
153
+ licenses: []
154
+ post_install_message:
155
+ rdoc_options: []
156
+ require_paths:
157
+ - lib
158
+ required_ruby_version: !ruby/object:Gem::Requirement
159
+ none: false
160
+ requirements:
161
+ - - ! '>='
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ required_rubygems_version: !ruby/object:Gem::Requirement
165
+ none: false
166
+ requirements:
167
+ - - ! '>='
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ requirements: []
171
+ rubyforge_project:
172
+ rubygems_version: 1.8.10
173
+ signing_key:
174
+ specification_version: 3
175
+ summary: Client for PRX OAuth2 API (v2)
176
+ test_files:
177
+ - test/helper.rb
178
+ - test/test_account.rb
179
+ - test/test_audio_file.rb
180
+ - test/test_audio_version.rb
181
+ - test/test_client.rb
182
+ - test/test_network.rb
183
+ - test/test_piece.rb
184
+ - test/test_series.rb
185
+ - test/test_user.rb