twaudio-ruby 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.
- data/CHANGELOG +1 -0
- data/LICENSE +22 -0
- data/Manifest +8 -0
- data/README.textile +49 -0
- data/Rakefile +10 -0
- data/lib/multipart/post.rb +76 -0
- data/lib/twaudio.rb +43 -0
- data/twaudio-ruby.gemspec +33 -0
- metadata +80 -0
data/CHANGELOG
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
v0.1 Initial release
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2009 Massive Robot Ltd.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following
|
10
|
+
conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest
ADDED
data/README.textile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
h1. twaud.io bindings for Ruby
|
2
|
+
|
3
|
+
This gem provides bindings to http://twaud.io which allows you to post audio to twitter.
|
4
|
+
|
5
|
+
It's crazy simple and depends on "HTTParty":http://github.com/jnunemaker/httparty. I've not
|
6
|
+
added it as a gem dependency because there are various forks of HTTParty about that you
|
7
|
+
might want to use and I don't want to prescribe a certain one
|
8
|
+
|
9
|
+
<pre>
|
10
|
+
<code>
|
11
|
+
|
12
|
+
require 'rubygems'
|
13
|
+
require 'twaudio'
|
14
|
+
|
15
|
+
twaudio = Twaudio.new 'twitter_user', 'twitter_pass'
|
16
|
+
|
17
|
+
# get details of a clip
|
18
|
+
|
19
|
+
twaudio.sound('4J')
|
20
|
+
=> {"message"=>"testing twaudio ruby bindings", "user"=>"danwrong", "listens"=>3,
|
21
|
+
"url"=>"http://twaud.io/4J", "audio_url"=>"http://twaud.io/audio/4J",
|
22
|
+
"created_at"=>"Thu, 09 Jul 2009 09:58:48 +0000"}
|
23
|
+
|
24
|
+
twaudio.user('danwrong')
|
25
|
+
=> [{"message"=>"testing twaudio ruby bindings", "user"=>"danwrong",
|
26
|
+
"listens"=>3, "url"=>"http://twaud.io/4J", "audio_url"=>"http://twaud.io/audio/4J",
|
27
|
+
"created_at"=>"Thu, 09 Jul 2009 09:58:48 +0000"}, {"message"=>"Atmosphere @ Scala",
|
28
|
+
"user"=>"danwrong", "listens"=>56, "url"=>"http://twaud.io/0k",
|
29
|
+
"audio_url"=>"http://twaud.io/audio/0k",
|
30
|
+
"created_at"=>"Wed, 24 Jun 2009 20:21:11 +0000"},
|
31
|
+
{"message"=>"It always freaks me out when this comes on when I have iTunes on shuffle...",
|
32
|
+
"user"=>"danwrong", "listens"=>69, "url"=>"http://twaud.io/sd",
|
33
|
+
"audio_url"=>"http://twaud.io/audio/sd", "created_at"=>"Fri, 19 Jun 2009 10:56:25 +0000"},
|
34
|
+
|
35
|
+
# ...and so on
|
36
|
+
|
37
|
+
dope_funky_fresh_tune = File.new('mc_flaps.mp3')
|
38
|
+
|
39
|
+
twaudio.upload('this shit is the flyest!!!!', dope_funky_fresh_tune)
|
40
|
+
=> {"message"=>"this shit is the flyest!!!!", "user"=>"danwrong", "listens"=>0,
|
41
|
+
"url"=>"http://twaud.io/34j4", "audio_url"=>"http://twaud.io/audio/34j4",
|
42
|
+
"created_at"=>"Thu, 09 Jul 2009 09:58:48 +0000"}
|
43
|
+
|
44
|
+
</code>
|
45
|
+
</pre>
|
46
|
+
|
47
|
+
At the moment it's just a stupidly thin wrapper around HTTParty but it does the job.
|
48
|
+
|
49
|
+
I'll probably beef it up a little as needed.
|
data/Rakefile
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'echoe'
|
2
|
+
|
3
|
+
Echoe.new("twaudio-ruby") do |p|
|
4
|
+
p.author = "Dan Webb"
|
5
|
+
p.email = 'dan@danwebb.net'
|
6
|
+
p.summary = "Dirt simple API for twaud.io"
|
7
|
+
p.url = "http://github.com/danwrong/twaudio-ruby/"
|
8
|
+
p.retain_gemspec = true
|
9
|
+
p.runtime_dependencies = ['mime-types']
|
10
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# From here: http://stackoverflow.com/questions/184178/ruby-how-to-post-a-file-via-http-as-multipart-form-data
|
2
|
+
require 'mime/types'
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
|
6
|
+
module Multipart
|
7
|
+
VERSION = "1.0.0" unless const_defined?(:VERSION)
|
8
|
+
|
9
|
+
class Post
|
10
|
+
attr_reader :headers, :body
|
11
|
+
|
12
|
+
DEFAULT_OPTIONS = {
|
13
|
+
:boundary => '0123456789RUBYRUBYRUBYRUBY9876543210',
|
14
|
+
:headers => {}
|
15
|
+
}
|
16
|
+
|
17
|
+
def initialize(params, options={})
|
18
|
+
@options = DEFAULT_OPTIONS.merge(options)
|
19
|
+
@params = params
|
20
|
+
|
21
|
+
prepare_query
|
22
|
+
end
|
23
|
+
|
24
|
+
protected
|
25
|
+
|
26
|
+
def prepare_query
|
27
|
+
parts = @params.collect do |k, v|
|
28
|
+
if v.respond_to?(:path) && v.respond_to?(:read)
|
29
|
+
FileParam.new(k, v.path, v.read)
|
30
|
+
else
|
31
|
+
StringParam.new(k, v)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
@headers = {
|
36
|
+
'Content-Type' => "multipart/form-data; boundary=#{@options[:boundary]}"
|
37
|
+
}.merge(@options[:headers])
|
38
|
+
|
39
|
+
@body = parts.collect do |part|
|
40
|
+
"--#{@options[:boundary]}\r\n#{part.to_multipart}"
|
41
|
+
end.join("")
|
42
|
+
|
43
|
+
@body << "--#{@options[:boundary]}--"
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
class StringParam
|
49
|
+
attr_accessor :k, :v
|
50
|
+
|
51
|
+
def initialize(k, v)
|
52
|
+
@k = k
|
53
|
+
@v = v
|
54
|
+
end
|
55
|
+
|
56
|
+
def to_multipart
|
57
|
+
return "Content-Disposition: form-data; name=\"#{URI::encode(k)}\"\r\n\r\n#{v}\r\n"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
class FileParam
|
62
|
+
attr_accessor :k, :filename, :content
|
63
|
+
|
64
|
+
def initialize(k, filename, content)
|
65
|
+
@k = k
|
66
|
+
@filename = filename
|
67
|
+
@content = content
|
68
|
+
end
|
69
|
+
|
70
|
+
def to_multipart
|
71
|
+
mime_type = MIME::Types.type_for(filename)[0] || MIME::Types["application/octet-stream"][0]
|
72
|
+
return "Content-Disposition: form-data; name=\"#{URI::encode(k)}\"; filename=\"#{ filename }\"\r\n" +
|
73
|
+
"Content-Type: #{ mime_type.simplified }\r\n\r\n#{ content }\r\n"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
data/lib/twaudio.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'multipart/post'
|
2
|
+
require 'httparty'
|
3
|
+
|
4
|
+
class Twaudio
|
5
|
+
include HTTParty
|
6
|
+
|
7
|
+
base_uri 'twaud.io'
|
8
|
+
|
9
|
+
def initialize(username='', password='')
|
10
|
+
@username = username
|
11
|
+
@password = password
|
12
|
+
end
|
13
|
+
|
14
|
+
def sound(id)
|
15
|
+
self.class.get("/api/v1/#{id}.json")
|
16
|
+
end
|
17
|
+
|
18
|
+
def user(login)
|
19
|
+
self.class.get("/api/v1/users/#{login}.json")
|
20
|
+
end
|
21
|
+
|
22
|
+
def upload(message, file, tweet_this=false)
|
23
|
+
params = {
|
24
|
+
'sound[message]' => message,
|
25
|
+
'sound[file]' => file,
|
26
|
+
'username' => @username,
|
27
|
+
'password' => @password
|
28
|
+
}
|
29
|
+
|
30
|
+
params[:tweet_this] = 'true' if tweet_this
|
31
|
+
|
32
|
+
self.class.multipart_post("/api/v1/upload.json", :query => params)
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.multipart_post(path, options={})
|
36
|
+
multipart_post = Multipart::Post.new(options.delete(:query))
|
37
|
+
|
38
|
+
options[:body] = multipart_post.body
|
39
|
+
options[:headers] = (options[:headers] || {}).merge(multipart_post.headers)
|
40
|
+
|
41
|
+
post path, options
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{twaudio-ruby}
|
5
|
+
s.version = "0.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Dan Webb"]
|
9
|
+
s.date = %q{2009-07-09}
|
10
|
+
s.description = %q{Dirt simple API for twaud.io}
|
11
|
+
s.email = %q{dan@danwebb.net}
|
12
|
+
s.extra_rdoc_files = ["CHANGELOG", "lib/multipart/post.rb", "lib/twaudio.rb", "LICENSE", "README.textile"]
|
13
|
+
s.files = ["CHANGELOG", "lib/multipart/post.rb", "lib/twaudio.rb", "LICENSE", "Manifest", "Rakefile", "README.textile", "twaudio-ruby.gemspec"]
|
14
|
+
s.homepage = %q{http://github.com/danwrong/twaudio-ruby/}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Twaudio-ruby", "--main", "README.textile"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{twaudio-ruby}
|
18
|
+
s.rubygems_version = %q{1.3.4}
|
19
|
+
s.summary = %q{Dirt simple API for twaud.io}
|
20
|
+
|
21
|
+
if s.respond_to? :specification_version then
|
22
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
|
+
s.specification_version = 3
|
24
|
+
|
25
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
26
|
+
s.add_runtime_dependency(%q<mime-types>, [">= 0"])
|
27
|
+
else
|
28
|
+
s.add_dependency(%q<mime-types>, [">= 0"])
|
29
|
+
end
|
30
|
+
else
|
31
|
+
s.add_dependency(%q<mime-types>, [">= 0"])
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: twaudio-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.1"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dan Webb
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-07-09 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: mime-types
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description: Dirt simple API for twaud.io
|
26
|
+
email: dan@danwebb.net
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- CHANGELOG
|
33
|
+
- lib/multipart/post.rb
|
34
|
+
- lib/twaudio.rb
|
35
|
+
- LICENSE
|
36
|
+
- README.textile
|
37
|
+
files:
|
38
|
+
- CHANGELOG
|
39
|
+
- lib/multipart/post.rb
|
40
|
+
- lib/twaudio.rb
|
41
|
+
- LICENSE
|
42
|
+
- Manifest
|
43
|
+
- Rakefile
|
44
|
+
- README.textile
|
45
|
+
- twaudio-ruby.gemspec
|
46
|
+
has_rdoc: true
|
47
|
+
homepage: http://github.com/danwrong/twaudio-ruby/
|
48
|
+
licenses: []
|
49
|
+
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options:
|
52
|
+
- --line-numbers
|
53
|
+
- --inline-source
|
54
|
+
- --title
|
55
|
+
- Twaudio-ruby
|
56
|
+
- --main
|
57
|
+
- README.textile
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: "0"
|
65
|
+
version:
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: "1.2"
|
71
|
+
version:
|
72
|
+
requirements: []
|
73
|
+
|
74
|
+
rubyforge_project: twaudio-ruby
|
75
|
+
rubygems_version: 1.3.4
|
76
|
+
signing_key:
|
77
|
+
specification_version: 3
|
78
|
+
summary: Dirt simple API for twaud.io
|
79
|
+
test_files: []
|
80
|
+
|