simple_tumblr 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/simple_tumblr/version.rb +3 -0
- data/lib/simple_tumblr.rb +89 -0
- metadata +136 -0
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'active_support/core_ext'
|
2
|
+
require 'httparty'
|
3
|
+
|
4
|
+
class SimpleTumblr
|
5
|
+
include Enumerable, HTTParty
|
6
|
+
|
7
|
+
attr_accessor :options
|
8
|
+
base_uri 'api.tumblr.com'
|
9
|
+
|
10
|
+
def initialize(options = {})
|
11
|
+
self.options = options
|
12
|
+
end
|
13
|
+
|
14
|
+
def posts(options = {})
|
15
|
+
self.options = self.options.merge(options)
|
16
|
+
self
|
17
|
+
end
|
18
|
+
|
19
|
+
%w[text quote link answer video audio photo].each do |type|
|
20
|
+
define_method(type) do
|
21
|
+
posts(type: type)
|
22
|
+
end
|
23
|
+
|
24
|
+
define_method(type.pluralize) do
|
25
|
+
posts(type: type)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
%w[id limit offset tag type].each do |scope|
|
30
|
+
define_method(scope) do |arg|
|
31
|
+
posts(scope.to_sym => arg)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def each(&block)
|
36
|
+
response = self.class.get("/v2/blog/#{self.options.delete(:hostname)}/posts", query: @options)
|
37
|
+
raise response['meta']['msg'] unless response.success?
|
38
|
+
|
39
|
+
response['response']['posts'].map { |data| Post.new(data) }.each(&block)
|
40
|
+
end
|
41
|
+
|
42
|
+
class << self
|
43
|
+
def method_missing(*args)
|
44
|
+
method, options = args
|
45
|
+
|
46
|
+
new.respond_to?(method) ? new(options).send(method) : super
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class Post
|
51
|
+
def initialize(data)
|
52
|
+
self.data = data.with_indifferent_access
|
53
|
+
end
|
54
|
+
|
55
|
+
delegate :inspect, :[], to: :data
|
56
|
+
|
57
|
+
def <=>(other)
|
58
|
+
self[:timestamp] <=> other[:timestamp]
|
59
|
+
end
|
60
|
+
|
61
|
+
def method_missing(*args)
|
62
|
+
method = args.first.to_sym
|
63
|
+
data.has_key?(method) ? data[method] : super
|
64
|
+
end
|
65
|
+
|
66
|
+
def title
|
67
|
+
attribute_presence(:title, :caption, :text)
|
68
|
+
end
|
69
|
+
alias_method :to_s, :title
|
70
|
+
|
71
|
+
def body
|
72
|
+
attribute_presence(:body)
|
73
|
+
end
|
74
|
+
|
75
|
+
def url
|
76
|
+
attribute_presence(:url, :link_url, :post_url)
|
77
|
+
end
|
78
|
+
|
79
|
+
private
|
80
|
+
attr_accessor :data
|
81
|
+
|
82
|
+
def attribute_presence(*attributes)
|
83
|
+
begin
|
84
|
+
attribute = self[attributes.shift]
|
85
|
+
end while attribute.blank?
|
86
|
+
attribute
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
metadata
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simple_tumblr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Mario Uher
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-01-09 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activesupport
|
16
|
+
requirement: &70121662354260 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.x
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70121662354260
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: httparty
|
27
|
+
requirement: &70121662353340 !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: *70121662353340
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: i18n
|
38
|
+
requirement: &70121662352300 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70121662352300
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: minitest
|
49
|
+
requirement: &70121662351260 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70121662351260
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: purdytest
|
60
|
+
requirement: &70121662350620 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70121662350620
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: &70121662349840 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *70121662349840
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: vcr
|
82
|
+
requirement: &70121662365120 !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: *70121662365120
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: webmock
|
93
|
+
requirement: &70121662364280 !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: *70121662364280
|
102
|
+
description: SimpleTumblr provides a simple – ActiveRecord::Relation like – way to
|
103
|
+
interact with the Tumblr API.
|
104
|
+
email: uher.mario@gmail.com
|
105
|
+
executables: []
|
106
|
+
extensions: []
|
107
|
+
extra_rdoc_files: []
|
108
|
+
files:
|
109
|
+
- lib/simple_tumblr/version.rb
|
110
|
+
- lib/simple_tumblr.rb
|
111
|
+
homepage: https://www.github.com/haihappen/simple_tumblr
|
112
|
+
licenses: []
|
113
|
+
post_install_message:
|
114
|
+
rdoc_options: []
|
115
|
+
require_paths:
|
116
|
+
- lib
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
119
|
+
requirements:
|
120
|
+
- - ! '>='
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
none: false
|
125
|
+
requirements:
|
126
|
+
- - ! '>='
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
requirements: []
|
130
|
+
rubyforge_project:
|
131
|
+
rubygems_version: 1.8.13
|
132
|
+
signing_key:
|
133
|
+
specification_version: 3
|
134
|
+
summary: A simple way to use the Tumblr™ API in Ruby.
|
135
|
+
test_files: []
|
136
|
+
has_rdoc:
|