audiosocket 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source :rubygems
2
+ gemspec
@@ -1,22 +1,10 @@
1
- = Audiosocket Ruby Client
1
+ # Audiosocket Ruby Client
2
2
 
3
- * http://github.com/audiosocket/ruby-client
3
+ An authentication client for Audiosocket's music discovery and licensing API.
4
4
 
5
- == Description
5
+ ## License (MIT)
6
6
 
7
- Access to Audiosocket's music and media management API.
8
-
9
- == Examples
10
-
11
- FIX (code sample of usage)
12
-
13
- == Installation
14
-
15
- $ gem install audiosocket
16
-
17
- == License
18
-
19
- Copyright 2010 Audiosocket (it@audiosocket.com)
7
+ Copyright 2010-2011 Audiosocket (it@audiosocket.com)
20
8
 
21
9
  Permission is hereby granted, free of charge, to any person obtaining
22
10
  a copy of this software and associated documentation files (the
data/Rakefile CHANGED
@@ -1,13 +1 @@
1
- require "hoe"
2
-
3
- Hoe.plugins.delete :rubyforge
4
- Hoe.plugin :doofus, :git, :isolate
5
-
6
- Hoe.spec "audiosocket" do
7
- developer "Audiosocket", "it@audiosocket.com"
8
-
9
- self.extra_rdoc_files = Dir["*.rdoc"]
10
- self.history_file = "CHANGELOG.rdoc"
11
- self.readme_file = "README.rdoc"
12
- self.testlib = :minitest
13
- end
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,19 @@
1
+ $:.unshift "lib"
2
+ require "audiosocket/version"
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Audiosocket"]
6
+ gem.email = ["it@audiosocket.com"]
7
+ gem.description = "An authentication client for the Audiosocket API."
8
+ gem.summary = "Helps authenticate users and generate Audiosocket API tokens."
9
+
10
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename f }
11
+ gem.files = `git ls-files`.split "\n"
12
+ gem.homepage = "https://github.com/audiosocket/ruby-client"
13
+ gem.name = "audiosocket"
14
+ gem.require_paths = ["lib"]
15
+ gem.test_files = `git ls-files -- test/*`.split "\n"
16
+ gem.version = Audiosocket::VERSION
17
+
18
+ gem.add_dependency "faraday", "~> 0.7"
19
+ end
data/lib/audiosocket.rb CHANGED
@@ -1,46 +1,2 @@
1
- require "configlet"
2
- require "rest_client"
3
-
4
- module Audiosocket
5
- extend Configlet
6
-
7
- # Duh.
8
-
9
- VERSION = "0.0.3"
10
-
11
- config :audiosocket do
12
- default :token => "no-token-provided"
13
- default :url => "http://audiosocket.com/api/v3"
14
- end
15
-
16
- RestClient.add_before_execution_proc do |req, params|
17
- if params[:url].include? self[:url]
18
- req["X-Audiosocket-Token"] = self[:token]
19
- end
20
- end
21
-
22
- def self.delete url, headers = {}, &block
23
- RestClient.delete maybe_prefix(url), headers, &block
24
- end
25
-
26
- def self.get url, headers = {}, &block
27
- RestClient.get maybe_prefix(url), headers, &block
28
- end
29
-
30
- def self.head url, headers = {}, &block
31
- RestClient.head maybe_prefix(url), headers, &block
32
- end
33
-
34
- def self.post url, payload, headers = {}, &block
35
- RestClient.post maybe_prefix(url), payload, headers, &block
36
- end
37
-
38
- def self.put url, payload, headers = {}, &block
39
- RestClient.put maybe_prefix(url), payload, headers, &block
40
- end
41
-
42
- def self.maybe_prefix url #:nodoc:
43
- return url if /^http/ =~ url
44
- File.join self[:url], url
45
- end
46
- end
1
+ require "audiosocket/client"
2
+ require "audiosocket/version"
@@ -0,0 +1,70 @@
1
+ require "faraday"
2
+ require "json"
3
+
4
+ module Audiosocket
5
+ class Client
6
+ attr_reader :conn
7
+ attr_reader :url
8
+
9
+ def initialize options = {}
10
+ @url = options[:url] || "https://api.audiosocket.com/v5"
11
+
12
+
13
+ @conn = Faraday.new url: @url do |f|
14
+ f.use Faraday::Request::JSON
15
+ f.use Faraday::Adapter::NetHttp
16
+ end
17
+
18
+ @conn.headers["X-Audiosocket-Token"] =
19
+ options.values_at(:token, :uid).compact.join ":"
20
+ end
21
+
22
+ # Auth a user given a temporary token or email and password.
23
+
24
+ def auth email_or_token, password = nil
25
+ password ? post("auth", email: email_or_token, password: password) :
26
+ post("auth/#{email_or_token}")
27
+ end
28
+
29
+ # Send a GET to the API, handling the response.
30
+
31
+ def get *args, &block
32
+ handle @conn.get *args, &block
33
+ end
34
+
35
+ # Handle and transform Faraday's response. `404` responses return
36
+ # `nil`. Responses from `200` to `299` and `422` parse the body as
37
+ # JSON.
38
+
39
+ def handle res
40
+ case res.status
41
+ when 200..299, 422 then JSON.parse res.body
42
+ when 404 then nil
43
+ else raise "#{res.status}: #{res.body}"
44
+ end
45
+ end
46
+
47
+ # Send a POST to the API, handling the response.
48
+
49
+ def post *args, &block
50
+ handle @conn.post *args, &block
51
+ end
52
+
53
+ # Send a PUT to the API, handling the response.
54
+
55
+ def put *args, &block
56
+ handle @conn.put *args, &block
57
+ end
58
+
59
+ def to_s
60
+ "#<Audiosocket::Client #{url}>"
61
+ end
62
+
63
+ # Create a temporary token for the client's current token/uid
64
+ # credentials.
65
+
66
+ def tokenize
67
+ post("token")["token"]
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,3 @@
1
+ module Audiosocket
2
+ VERSION = "0.1.0"
3
+ end
metadata CHANGED
@@ -1,154 +1,64 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: audiosocket
3
- version: !ruby/object:Gem::Version
4
- hash: 25
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 3
10
- version: 0.0.3
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Audiosocket
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-02-10 00:00:00 -06:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- name: configlet
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ~>
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 2
32
- - 0
33
- version: "2.0"
34
- type: :runtime
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: rest-client
38
- prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
12
+ date: 2011-11-02 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: faraday
16
+ requirement: &70115962937120 !ruby/object:Gem::Requirement
40
17
  none: false
41
- requirements:
18
+ requirements:
42
19
  - - ~>
43
- - !ruby/object:Gem::Version
44
- hash: 5
45
- segments:
46
- - 1
47
- - 5
48
- version: "1.5"
20
+ - !ruby/object:Gem::Version
21
+ version: '0.7'
49
22
  type: :runtime
50
- version_requirements: *id002
51
- - !ruby/object:Gem::Dependency
52
- name: fakeweb
53
- prerelease: false
54
- requirement: &id003 !ruby/object:Gem::Requirement
55
- none: false
56
- requirements:
57
- - - ~>
58
- - !ruby/object:Gem::Version
59
- hash: 11
60
- segments:
61
- - 1
62
- - 2
63
- version: "1.2"
64
- type: :development
65
- version_requirements: *id003
66
- - !ruby/object:Gem::Dependency
67
- name: minitest
68
- prerelease: false
69
- requirement: &id004 !ruby/object:Gem::Requirement
70
- none: false
71
- requirements:
72
- - - ~>
73
- - !ruby/object:Gem::Version
74
- hash: 3
75
- segments:
76
- - 1
77
- - 6
78
- version: "1.6"
79
- type: :development
80
- version_requirements: *id004
81
- - !ruby/object:Gem::Dependency
82
- name: hoe
83
23
  prerelease: false
84
- requirement: &id005 !ruby/object:Gem::Requirement
85
- none: false
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- hash: 41
90
- segments:
91
- - 2
92
- - 9
93
- - 1
94
- version: 2.9.1
95
- type: :development
96
- version_requirements: *id005
97
- description: Access to Audiosocket's music and media management API.
98
- email:
24
+ version_requirements: *70115962937120
25
+ description: An authentication client for the Audiosocket API.
26
+ email:
99
27
  - it@audiosocket.com
100
28
  executables: []
101
-
102
29
  extensions: []
103
-
104
- extra_rdoc_files:
105
- - Manifest.txt
106
- - CHANGELOG.rdoc
107
- - README.rdoc
108
- files:
109
- - .autotest
110
- - CHANGELOG.rdoc
111
- - Isolate
112
- - Manifest.txt
113
- - README.rdoc
30
+ extra_rdoc_files: []
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - README.md
114
35
  - Rakefile
36
+ - audiosocket.gemspec
115
37
  - lib/audiosocket.rb
116
- - test/test_audiosocket.rb
117
- - .gemtest
118
- has_rdoc: true
119
- homepage: http://github.com/audiosocket/ruby-client
38
+ - lib/audiosocket/client.rb
39
+ - lib/audiosocket/version.rb
40
+ homepage: https://github.com/audiosocket/ruby-client
120
41
  licenses: []
121
-
122
42
  post_install_message:
123
- rdoc_options:
124
- - --main
125
- - README.rdoc
126
- require_paths:
43
+ rdoc_options: []
44
+ require_paths:
127
45
  - lib
128
- required_ruby_version: !ruby/object:Gem::Requirement
46
+ required_ruby_version: !ruby/object:Gem::Requirement
129
47
  none: false
130
- requirements:
131
- - - ">="
132
- - !ruby/object:Gem::Version
133
- hash: 3
134
- segments:
135
- - 0
136
- version: "0"
137
- required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
53
  none: false
139
- requirements:
140
- - - ">="
141
- - !ruby/object:Gem::Version
142
- hash: 3
143
- segments:
144
- - 0
145
- version: "0"
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
146
58
  requirements: []
147
-
148
- rubyforge_project: audiosocket
149
- rubygems_version: 1.5.1
59
+ rubyforge_project:
60
+ rubygems_version: 1.8.11
150
61
  signing_key:
151
62
  specification_version: 3
152
- summary: Access to Audiosocket's music and media management API.
153
- test_files:
154
- - test/test_audiosocket.rb
63
+ summary: Helps authenticate users and generate Audiosocket API tokens.
64
+ test_files: []
data/.autotest DELETED
@@ -1,5 +0,0 @@
1
- require "autotest/restart"
2
-
3
- Autotest.add_hook :initialize do |at|
4
- at.testlib = "minitest/autorun"
5
- end
data/.gemtest DELETED
File without changes
data/CHANGELOG.rdoc DELETED
@@ -1,3 +0,0 @@
1
- === 0.0.0 / 2010-05-12
2
-
3
- * Birthday!
data/Isolate DELETED
@@ -1,7 +0,0 @@
1
- gem "configlet", "~> 2.0"
2
- gem "rest-client", "~> 1.5"
3
-
4
- env :development do
5
- gem "fakeweb", "~> 1.2"
6
- gem "minitest", "~> 1.6"
7
- end
data/Manifest.txt DELETED
@@ -1,8 +0,0 @@
1
- .autotest
2
- CHANGELOG.rdoc
3
- Isolate
4
- Manifest.txt
5
- README.rdoc
6
- Rakefile
7
- lib/audiosocket.rb
8
- test/test_audiosocket.rb
@@ -1,10 +0,0 @@
1
- require "isolate/now"
2
- require "minitest/autorun"
3
- require "audiosocket"
4
-
5
- class TestAudiosocket < MiniTest::Unit::TestCase
6
- def test_self_config_defaults
7
- assert_equal "no-token-provided", Audiosocket[:token]
8
- assert_equal "http://audiosocket.com/api/v3", Audiosocket[:url]
9
- end
10
- end