tumblr_client 0.8.2 → 0.8.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 928807e6f2d5769cdd3fb00545611a035f569575
4
- data.tar.gz: f587e06329f739c36c3b8b66f4a0fc9ee48c45c3
3
+ metadata.gz: 8be1e20d35a7a006f0e6b99acd2edec883b8185b
4
+ data.tar.gz: d2bb7b98c0d01a881cca25c71a0f52e88000fcbe
5
5
  SHA512:
6
- metadata.gz: 98c178bf683e4f627a8091a3f1a6fb1ce4eaed04b1ab67c1dfd369ea0df5a6fcad5cd9cf24d472939a9ad21bd849a131f7ed1031e29f398ede17251ce58efd7d
7
- data.tar.gz: 452499e743723afd1b0fe30645a86423d4ad80c2a6f31d524e2ae194c03ccff0e35aa4b7639ea37bc369ab95cb05b4ff45d6a4b14e87a61670fd9bcccbbfa959
6
+ metadata.gz: a35845b69e889b99d07f130430eedda33d882dc5ad7ac78110a2c3d01a5a1365a9b142a003db5575990b2cf8ad5c666b7be66d3478f1d054fa3dd599d09d57ca
7
+ data.tar.gz: 4241c43f2640ba5a489740e06e20bb61bae303d4067df6c41da6510fb37e8223c3abcf4fdc4ed62149cc1f07337928c4a497e11727fabe0ada7a658e95cf709c
data/.gitignore CHANGED
@@ -9,3 +9,5 @@ coverage
9
9
  .rspec
10
10
 
11
11
  Gemfile.lock
12
+
13
+ .bundle
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Tumblr Ruby Gem
2
2
 
3
- [![Build Status](https://secure.travis-ci.org/tumblr/tumblr_client.png)](http://travis-ci.org/tumblr/tumblr_client)
3
+ [![Gem Version](https://badge.fury.io/rb/tumblr_client.png)](http://badge.fury.io/rb/tumblr_client) [![Build Status](https://secure.travis-ci.org/tumblr/tumblr_client.png)](http://travis-ci.org/tumblr/tumblr_client)
4
4
 
5
5
  This is the official Ruby wrapper for the Tumblr v2 API. It supports all
6
6
  endpoints currently available on the
@@ -5,7 +5,8 @@ module Tumblr
5
5
  module Connection
6
6
 
7
7
  def connection(options={})
8
-
8
+ options = options.clone
9
+
9
10
  default_options = {
10
11
  :headers => {
11
12
  :accept => 'application/json',
@@ -14,7 +15,7 @@ module Tumblr
14
15
  :url => "http://#{api_host}/"
15
16
  }
16
17
 
17
- client = options[:client] ||= Faraday.default_adapter
18
+ client = options.delete(:client) || Faraday.default_adapter
18
19
 
19
20
  Faraday.new("http://#{api_host}/", default_options.merge(options)) do |conn|
20
21
  data = { :api_host => api_host }.merge(credentials)
@@ -4,9 +4,13 @@ module Tumblr
4
4
  module Post
5
5
 
6
6
  STANDARD_POST_OPTIONS = [:state, :tags, :tweet, :date, :markdown, :slug, :format]
7
+ DATA_POST_TYPES = [:audio, :video, :photo]
8
+ VALID_POST_TYPES = DATA_POST_TYPES + [:quote, :text, :link, :chat]
7
9
 
8
10
  def edit(blog_name, options = {})
9
11
  convert_source_array :source, options
12
+ extract_data!(options) if DATA_POST_TYPES.include?(options[:type])
13
+
10
14
  post(blog_path(blog_name, 'post/edit'), options)
11
15
  end
12
16
 
@@ -81,6 +85,14 @@ module Tumblr
81
85
  post(post_path(blog_name), options)
82
86
  end
83
87
 
88
+ def create_post(type, blog_name, options = {})
89
+ if VALID_POST_TYPES.include?(type)
90
+ send(type, blog_name, options)
91
+ else
92
+ raise ArgumentError.new "\"#{type}\" is not a valid post type"
93
+ end
94
+ end
95
+
84
96
  private
85
97
 
86
98
  def post_path(blog_name)
@@ -105,9 +117,15 @@ module Tumblr
105
117
 
106
118
  if Array === data
107
119
  data.each.with_index do |filepath, idx|
108
- mime_type = extract_mimetype(filepath)
109
- options["data[#{idx}]"] = Faraday::UploadIO.new(filepath, mime_type)
120
+ if filepath.is_a?(Faraday::UploadIO)
121
+ options["data[#{idx}]"] = filepath
122
+ else
123
+ mime_type = extract_mimetype(filepath)
124
+ options["data[#{idx}]"] = Faraday::UploadIO.new(filepath, mime_type)
125
+ end
110
126
  end
127
+ elsif data.is_a?(Faraday::UploadIO)
128
+ options["data"] = data
111
129
  else
112
130
  mime_type = extract_mimetype(data)
113
131
  options["data"] = Faraday::UploadIO.new(data, mime_type)
@@ -1,5 +1,5 @@
1
1
  module Tumblr
2
2
 
3
- VERSION = '0.8.2'
3
+ VERSION = '0.8.3'
4
4
 
5
5
  end
@@ -28,6 +28,56 @@ describe Tumblr::Post do
28
28
  end
29
29
 
30
30
  describe :edit do
31
+ [:photo, :audio, :video].each do |type|
32
+ describe type do
33
+ context 'when passing data as an array of filepaths' do
34
+ before do
35
+ fakefile = OpenStruct.new :read => file_data
36
+ File.stub(:open).with(file_path + '.jpg').and_return(fakefile)
37
+ client.should_receive(:post).once.with("v2/blog/#{blog_name}/post/edit", {
38
+ 'data[0]' => kind_of(Faraday::UploadIO),
39
+ :id => 123,
40
+ :type => type
41
+ }).and_return('response')
42
+ end
43
+
44
+ it 'should be able to pass data as an array of filepaths' do
45
+ r = client.edit blog_name, :data => [file_path + ".jpg"], :id => 123, :type => type
46
+ r.should == 'response'
47
+ end
48
+
49
+ it 'should be able to pass data as an array of uploadios' do
50
+ r = client.edit blog_name, :data => [Faraday::UploadIO.new(StringIO.new, 'image/jpeg')], :id => 123, :type => type
51
+ r.should == 'response'
52
+ end
53
+
54
+ end
55
+
56
+ context 'when passing data different ways' do
57
+
58
+ before do
59
+ fakefile = OpenStruct.new :read => file_data
60
+ File.stub(:open).with(file_path + '.jpg').and_return(fakefile)
61
+ client.should_receive(:post).once.with("v2/blog/#{blog_name}/post/edit", {
62
+ 'data' => kind_of(Faraday::UploadIO),
63
+ :id => 123,
64
+ :type => type
65
+ }).and_return('response')
66
+ end
67
+
68
+ it 'should be able to pass data as a single filepath' do
69
+ r = client.edit blog_name, :data => file_path + ".jpg", :id => 123, :type => type
70
+ r.should == 'response'
71
+ end
72
+
73
+ it 'should be able to pass data as a single uploadio' do
74
+ r = client.edit blog_name, :data => Faraday::UploadIO.new(StringIO.new, 'image/jpeg'), :id => 123, :type => type
75
+ r.should == 'response'
76
+ end
77
+
78
+ end
79
+ end
80
+ end
31
81
 
32
82
  it 'should make the correct call' do
33
83
  client.should_receive(:post).once.with("v2/blog/#{blog_name}/post/edit", {
@@ -36,7 +86,6 @@ describe Tumblr::Post do
36
86
  r = client.edit blog_name, :id => 123
37
87
  r.should == 'response'
38
88
  end
39
-
40
89
  end
41
90
 
42
91
  describe :reblog do
@@ -89,6 +138,35 @@ describe Tumblr::Post do
89
138
 
90
139
  end
91
140
 
141
+ describe :create_post do
142
+
143
+ let(:blog_name) { 'seejohnrun' }
144
+ let(:args) { { :source => 'somesource' } }
145
+
146
+ context 'with a valid post type' do
147
+
148
+ before do
149
+ client.should_receive(:photo).with(blog_name, args).and_return 'hi'
150
+ end
151
+
152
+ it 'should call the right method and grab the return' do
153
+ client.create_post(:photo, blog_name, args).should == 'hi'
154
+ end
155
+
156
+ end
157
+
158
+ context 'with an invalid post type' do
159
+
160
+ it 'should raise an error' do
161
+ lambda do
162
+ client.create_post(:fake, blog_name, args)
163
+ end.should raise_error ArgumentError, '"fake" is not a valid post type'
164
+ end
165
+
166
+ end
167
+
168
+ end
169
+
92
170
  # Complex post types
93
171
  [:photo, :audio, :video].each do |type|
94
172
 
@@ -119,6 +197,11 @@ describe Tumblr::Post do
119
197
  r.should == 'post'
120
198
  end
121
199
 
200
+ it 'should be able to pass data as an array of uploadios' do
201
+ r = client.send type, blog_name, :data => [Faraday::UploadIO.new(StringIO.new, 'image/jpeg')]
202
+ r.should == 'post'
203
+ end
204
+
122
205
  end
123
206
 
124
207
  context 'when passing data different ways' do
@@ -137,6 +220,11 @@ describe Tumblr::Post do
137
220
  r.should == 'post'
138
221
  end
139
222
 
223
+ it 'should be able to pass data as a single uploadio' do
224
+ r = client.send type, blog_name, :data => Faraday::UploadIO.new(StringIO.new, 'image/jpeg')
225
+ r.should == 'post'
226
+ end
227
+
140
228
  end
141
229
 
142
230
  # Only photos have source
@@ -2,8 +2,8 @@
2
2
  require File.join(File.dirname(__FILE__), 'lib/tumblr/version')
3
3
 
4
4
  Gem::Specification.new do |gem|
5
- gem.add_dependency 'faraday', '>= 0.8'
6
- gem.add_dependency 'faraday_middleware', '>= 0.8'
5
+ gem.add_dependency 'faraday', '~> 0.8.9'
6
+ gem.add_dependency 'faraday_middleware', '~> 0.8'
7
7
  gem.add_dependency 'json'
8
8
  gem.add_dependency 'simple_oauth'
9
9
  gem.add_dependency 'oauth'
@@ -21,7 +21,6 @@ Gem::Specification.new do |gem|
21
21
  gem.license = "Apache"
22
22
  gem.name = "tumblr_client"
23
23
  gem.require_paths = ["lib"]
24
- gem.required_rubygems_version = Gem::Requirement.new('>= 1.3.6')
25
24
  gem.summary = %q{Tumblr API wrapper}
26
25
  gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
27
26
  gem.version = Tumblr::VERSION
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tumblr_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ version: 0.8.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Bunting
@@ -9,34 +9,34 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-07 00:00:00.000000000 Z
12
+ date: 2014-06-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - '>='
18
+ - - ~>
19
19
  - !ruby/object:Gem::Version
20
- version: '0.8'
20
+ version: 0.8.9
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - '>='
25
+ - - ~>
26
26
  - !ruby/object:Gem::Version
27
- version: '0.8'
27
+ version: 0.8.9
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: faraday_middleware
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - '>='
32
+ - - ~>
33
33
  - !ruby/object:Gem::Version
34
34
  version: '0.8'
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - '>='
39
+ - - ~>
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0.8'
42
42
  - !ruby/object:Gem::Dependency
@@ -203,10 +203,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
203
203
  requirements:
204
204
  - - '>='
205
205
  - !ruby/object:Gem::Version
206
- version: 1.3.6
206
+ version: '0'
207
207
  requirements: []
208
208
  rubyforge_project:
209
- rubygems_version: 2.0.3
209
+ rubygems_version: 2.1.11
210
210
  signing_key:
211
211
  specification_version: 4
212
212
  summary: Tumblr API wrapper