tumbling 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +19 -0
- data/lib/tumbling/audio.rb +35 -0
- data/lib/tumbling/conversation.rb +35 -0
- data/lib/tumbling/link.rb +35 -0
- data/lib/tumbling/photo.rb +51 -0
- data/lib/tumbling/post.rb +35 -0
- data/lib/tumbling/quote.rb +36 -0
- data/lib/tumbling/resource.rb +69 -0
- data/lib/tumbling/video.rb +36 -0
- data/lib/tumbling.rb +25 -0
- data/script/console +3 -0
- data/tumbling.gemspec +19 -0
- metadata +75 -0
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2010 Cameron Cox
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Tumbling
|
2
|
+
class Audio < Resource
|
3
|
+
|
4
|
+
attr_accessor \
|
5
|
+
:id,
|
6
|
+
:url,
|
7
|
+
:date,
|
8
|
+
:format,
|
9
|
+
:slug,
|
10
|
+
:body,
|
11
|
+
:title,
|
12
|
+
:tags
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def self.from_api_attributes(attributes)
|
17
|
+
{
|
18
|
+
:id => attributes['id'],
|
19
|
+
:url => attributes['url_with_slug'],
|
20
|
+
:date => attributes['date_gmt'],
|
21
|
+
:format => attributes['format'],
|
22
|
+
:slug => attributes['slug'],
|
23
|
+
:body => attributes['audio_player'],
|
24
|
+
:title => attributes['audio_caption'],
|
25
|
+
:tags => attributes['tag']
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
#
|
30
|
+
# @return [String] get all posts with a type of regular
|
31
|
+
def self.type
|
32
|
+
'audio'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Tumbling
|
2
|
+
class Conversation < Resource
|
3
|
+
|
4
|
+
attr_accessor \
|
5
|
+
:id,
|
6
|
+
:url,
|
7
|
+
:date,
|
8
|
+
:format,
|
9
|
+
:slug,
|
10
|
+
:body,
|
11
|
+
:title,
|
12
|
+
:tags
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def self.from_api_attributes(attributes)
|
17
|
+
{
|
18
|
+
:id => attributes['id'],
|
19
|
+
:url => attributes['url_with_slug'],
|
20
|
+
:date => attributes['date_gmt'],
|
21
|
+
:format => attributes['format'],
|
22
|
+
:slug => attributes['slug'],
|
23
|
+
:body => attributes['conversation_text'],
|
24
|
+
:title => attributes['conversation_title'],
|
25
|
+
:tags => attributes['tag']
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
#
|
30
|
+
# @return [String] get all posts with a type of regular
|
31
|
+
def self.type
|
32
|
+
'conversation'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Tumbling
|
2
|
+
class Link < Resource
|
3
|
+
|
4
|
+
attr_accessor \
|
5
|
+
:id,
|
6
|
+
:url,
|
7
|
+
:date,
|
8
|
+
:format,
|
9
|
+
:slug,
|
10
|
+
:body,
|
11
|
+
:title,
|
12
|
+
:tags
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def self.from_api_attributes(attributes)
|
17
|
+
{
|
18
|
+
:id => attributes['id'],
|
19
|
+
:url => attributes['url_with_slug'],
|
20
|
+
:date => attributes['date_gmt'],
|
21
|
+
:format => attributes['format'],
|
22
|
+
:slug => attributes['slug'],
|
23
|
+
:body => attributes['link_url'],
|
24
|
+
:title => attributes['link_text'],
|
25
|
+
:tags => attributes['tag']
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
#
|
30
|
+
# @return [String] get all posts with a type of regular
|
31
|
+
def self.type
|
32
|
+
'link'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Tumbling
|
2
|
+
class Photo < Resource
|
3
|
+
|
4
|
+
attr_accessor \
|
5
|
+
:id,
|
6
|
+
:url,
|
7
|
+
:date,
|
8
|
+
:format,
|
9
|
+
:slug,
|
10
|
+
:body,
|
11
|
+
:title,
|
12
|
+
:images
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def self.from_api_attributes(attributes)
|
17
|
+
{
|
18
|
+
:id => attributes['id'],
|
19
|
+
:url => attributes['url_with_slug'],
|
20
|
+
:date => attributes['date_gmt'],
|
21
|
+
:format => attributes['format'],
|
22
|
+
:slug => attributes['slug'],
|
23
|
+
:body => build_body(attributes['photo_url']),
|
24
|
+
:title => attributes['photo_caption'],
|
25
|
+
:tags => attributes['tag']
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.build_body(urls)
|
30
|
+
|
31
|
+
urls.collect { |x| Image.new(x).to_html }
|
32
|
+
end
|
33
|
+
|
34
|
+
#
|
35
|
+
# @return [String] get all posts with a type of regular
|
36
|
+
def self.type
|
37
|
+
'photo'
|
38
|
+
end
|
39
|
+
|
40
|
+
class Image
|
41
|
+
attr_accessor :url, :alt
|
42
|
+
def initialize(url, alt = nil)
|
43
|
+
@url = url
|
44
|
+
@alt = alt
|
45
|
+
end
|
46
|
+
def to_html
|
47
|
+
"<img src=\"#{url}\" alt=\"#{alt}\" />"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Tumbling
|
2
|
+
class Post < Resource
|
3
|
+
|
4
|
+
attr_accessor \
|
5
|
+
:id,
|
6
|
+
:url,
|
7
|
+
:date,
|
8
|
+
:format,
|
9
|
+
:slug,
|
10
|
+
:body,
|
11
|
+
:title,
|
12
|
+
:tags
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def self.from_api_attributes(attributes)
|
17
|
+
{
|
18
|
+
:id => attributes['id'],
|
19
|
+
:url => attributes['url_with_slug'],
|
20
|
+
:date => attributes['date_gmt'],
|
21
|
+
:format => attributes['format'],
|
22
|
+
:slug => attributes['slug'],
|
23
|
+
:body => attributes['regular_body'],
|
24
|
+
:title => attributes['regular_title'],
|
25
|
+
:tags => attributes['tag']
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
#
|
30
|
+
# @return [String] get all posts with a type of regular
|
31
|
+
def self.type
|
32
|
+
'regular'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Tumbling
|
2
|
+
class Quote < Resource
|
3
|
+
|
4
|
+
attr_accessor \
|
5
|
+
:id,
|
6
|
+
:url,
|
7
|
+
:date,
|
8
|
+
:format,
|
9
|
+
:slug,
|
10
|
+
:body,
|
11
|
+
:title,
|
12
|
+
:tags,
|
13
|
+
:tags
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def self.from_api_attributes(attributes)
|
18
|
+
{
|
19
|
+
:id => attributes['id'],
|
20
|
+
:url => attributes['url_with_slug'],
|
21
|
+
:date => attributes['date_gmt'],
|
22
|
+
:format => attributes['format'],
|
23
|
+
:slug => attributes['slug'],
|
24
|
+
:body => attributes['quote_text'],
|
25
|
+
:title => attributes['quote_source'],
|
26
|
+
:tags => attributes['tag']
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
#
|
31
|
+
# @return [String] get all posts with a type of regular
|
32
|
+
def self.type
|
33
|
+
'quote'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module Tumbling
|
2
|
+
class Resource
|
3
|
+
include HTTParty
|
4
|
+
format :xml
|
5
|
+
|
6
|
+
def self.all
|
7
|
+
get_resources(type)
|
8
|
+
end
|
9
|
+
|
10
|
+
def type
|
11
|
+
self.class.type
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.build(attrs)
|
15
|
+
new from_api_attributes(attrs)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def initialize(hash = {})
|
21
|
+
hash.each do |key, value|
|
22
|
+
send("#{key}=", value)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.export_type_to_native_objects(results)
|
27
|
+
if results.kind_of?(Array)
|
28
|
+
@_results = []
|
29
|
+
results.each do |result|
|
30
|
+
@_results.push(export_type_to_native_object(result))
|
31
|
+
end
|
32
|
+
|
33
|
+
return @_results
|
34
|
+
else
|
35
|
+
return [export_type_to_native_object(results)]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.export_type_to_native_object(result)
|
40
|
+
type = (result['type'] == 'regular') ? 'post' : result['type']
|
41
|
+
object = Tumbling.const_get constantize_type(type)
|
42
|
+
object.build(result)
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.get_resources(type)
|
46
|
+
query = {}
|
47
|
+
query.merge!({ :type => type }) unless type.nil?
|
48
|
+
|
49
|
+
results = get '/api/read', :query => query
|
50
|
+
# return results
|
51
|
+
if results['tumblr']
|
52
|
+
return export_type_to_native_objects(results['tumblr']['posts']['post'])
|
53
|
+
else
|
54
|
+
[]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# The type of posts to get from the API
|
59
|
+
#
|
60
|
+
# @return [NilClass] nil for all post types
|
61
|
+
def self.type
|
62
|
+
nil
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.constantize_type(type)
|
66
|
+
type[0...1].upcase + type[1...type.length]
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Tumbling
|
2
|
+
class Video < Resource
|
3
|
+
|
4
|
+
attr_accessor \
|
5
|
+
:id,
|
6
|
+
:url,
|
7
|
+
:date,
|
8
|
+
:format,
|
9
|
+
:slug,
|
10
|
+
:body,
|
11
|
+
:title,
|
12
|
+
:tags,
|
13
|
+
:tags
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def self.from_api_attributes(attributes)
|
18
|
+
{
|
19
|
+
:id => attributes['id'],
|
20
|
+
:url => attributes['url_with_slug'],
|
21
|
+
:date => attributes['date_gmt'],
|
22
|
+
:format => attributes['format'],
|
23
|
+
:slug => attributes['slug'],
|
24
|
+
:body => attributes['video_player'],
|
25
|
+
:title => attributes['video_caption'],
|
26
|
+
:tags => attributes['tag']
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
#
|
31
|
+
# @return [String] get all posts with a type of regular
|
32
|
+
def self.type
|
33
|
+
'video'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/tumbling.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
3
|
+
module Tumbling
|
4
|
+
|
5
|
+
autoload :Resource, 'tumbling/resource'
|
6
|
+
autoload :Post, 'tumbling/post'
|
7
|
+
# quote, photo, link, chat, video, or audio
|
8
|
+
|
9
|
+
autoload :Audio, 'tumbling/audio'
|
10
|
+
autoload :Conversation, 'tumbling/conversation'
|
11
|
+
autoload :Link, 'tumbling/link'
|
12
|
+
autoload :Photo, 'tumbling/photo'
|
13
|
+
autoload :Quote, 'tumbling/quote'
|
14
|
+
autoload :Video, 'tumbling/video'
|
15
|
+
|
16
|
+
class << self
|
17
|
+
attr_accessor :email, :password
|
18
|
+
|
19
|
+
def blog=(blog)
|
20
|
+
Resource.base_uri "http://#{blog}.tumblr.com"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
Tumbling.blog = "proposable"
|
data/script/console
ADDED
data/tumbling.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{tumbling}
|
5
|
+
s.version = "0.0.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Cameron Cox"]
|
9
|
+
s.date = %q{2008-09-10}
|
10
|
+
s.email = %q{cameroncox@gmail.com}
|
11
|
+
s.extra_rdoc_files = ["LICENSE"]
|
12
|
+
s.files = Dir["**/**"]
|
13
|
+
s.homepage = %q{http://github.com/cameroncox/tumbling}
|
14
|
+
s.require_paths = ["lib"]
|
15
|
+
s.rubygems_version = %q{1.3.1}
|
16
|
+
s.summary = %q{Tumblr API Gem}
|
17
|
+
|
18
|
+
s.add_runtime_dependency(%q<httparty>, [">= 0.4.5"])
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tumbling
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Cameron Cox
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-09-10 00:00:00 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: httparty
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.4.5
|
24
|
+
version:
|
25
|
+
description:
|
26
|
+
email: cameroncox@gmail.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- LICENSE
|
33
|
+
files:
|
34
|
+
- lib/tumbling/audio.rb
|
35
|
+
- lib/tumbling/conversation.rb
|
36
|
+
- lib/tumbling/link.rb
|
37
|
+
- lib/tumbling/photo.rb
|
38
|
+
- lib/tumbling/post.rb
|
39
|
+
- lib/tumbling/quote.rb
|
40
|
+
- lib/tumbling/resource.rb
|
41
|
+
- lib/tumbling/video.rb
|
42
|
+
- lib/tumbling.rb
|
43
|
+
- LICENSE
|
44
|
+
- script/console
|
45
|
+
- tumbling.gemspec
|
46
|
+
has_rdoc: true
|
47
|
+
homepage: http://github.com/cameroncox/tumbling
|
48
|
+
licenses: []
|
49
|
+
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: "0"
|
60
|
+
version:
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: "0"
|
66
|
+
version:
|
67
|
+
requirements: []
|
68
|
+
|
69
|
+
rubyforge_project:
|
70
|
+
rubygems_version: 1.3.5
|
71
|
+
signing_key:
|
72
|
+
specification_version: 3
|
73
|
+
summary: Tumblr API Gem
|
74
|
+
test_files: []
|
75
|
+
|