tumblr-rb 1.0.0 → 1.1.0

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/README.md CHANGED
@@ -20,6 +20,13 @@ You can pass `tumblr` something from standard input, but you have to set your em
20
20
  $: echo 'Hello world.' | tumblr -a user@tumblr.com:supers3cretp4ssw0rd
21
21
  Published to Tumblr. The ID for this post is: 123456790
22
22
 
23
+ Or the credentials can come from a YAML file:
24
+
25
+ $ cat ~/.tumblrlogin
26
+ email: tumblruser@generic-email.com
27
+ password: myvoiceismypassport
28
+ $ echo 'Hello world. | tumblr --credentials ~/.tumblrlogin
29
+
23
30
  Try `tumblr --help` if you are in need of guidance. Read [tumblr(1)](http://mwunsch.github.com/tumblr/tumblr.1.html) for more information.
24
31
 
25
32
  ## Getting Started
@@ -101,12 +108,10 @@ To publish to Tumblr, do this:
101
108
 
102
109
  ## TODO:
103
110
 
104
- + Tumblr::Post needs methods for liking and unliking.
105
- + Add options to CLI for adding to queue, drafts, etc.
106
111
  + File-uploading for Photos, Videos, Audio (needs to get into Weary)
107
112
 
108
113
  ## Copyright
109
114
 
110
115
  The Tumblr gem is Copyright (c) 2010 Mark Wunsch and is licensed under the [MIT License](http://creativecommons.org/licenses/MIT/).
111
116
 
112
- Tumblr is Copyright (c) Tumblr, Inc. The Tumblr gem is NOT affiliated with Tumblr.
117
+ Tumblr is Copyright (c) Tumblr, Inc. The Tumblr gem is NOT affiliated with Tumblr, Inc.
data/bin/tumblr CHANGED
@@ -35,6 +35,8 @@ rescue LoadError
35
35
  end
36
36
 
37
37
  publisher = {}
38
+ publish_state = nil
39
+ group = nil
38
40
 
39
41
  ARGV.options do |option|
40
42
  option.banner = usage
@@ -42,15 +44,25 @@ ARGV.options do |option|
42
44
 
43
45
  auth_text = 'Email Address and Password, separated by a colon'
44
46
  option.on('-a EMAIL:PASSWORD', '--auth EMAIL:PASSWORD', auth_text) do |auth|
45
- credentials = auth.split(':')
46
- publisher[:email] = credentials[0]
47
- publisher[:password] = credentials[1]
47
+ publisher[:email],publisher[:password] = auth.split(':')
48
48
  end
49
49
 
50
50
  address_text = 'Email Address (will prompt for password)'
51
51
  option.on('-e EMAIL', '--email EMAIL', address_text) do |email|
52
52
  publisher[:email] = email
53
53
  end
54
+
55
+ option.on('--credentials FILE', 'A YAML file with "email" and "password" keys for authentication') do |file|
56
+ credentials = YAML.load(File.read(file))
57
+ publisher[:email] = credentials['email']
58
+ publisher[:password] = credentials['password']
59
+ end
60
+
61
+ option.on('-p','--publish', 'Publish the post immediately (ignores "state" parameter)') { publish_state = :published }
62
+ option.on('-q','--queue', 'Add the post to the queue') { publish_state = :queue }
63
+ option.on('-d','--draft', 'Save the post as a draft') { publish_state = :draft }
64
+
65
+ option.on('--group=GROUP','Publish to a group blog') {|value| group = value }
54
66
 
55
67
  option.separator ""
56
68
 
@@ -110,7 +122,11 @@ if !publisher[:email] || !publisher[:password]
110
122
  end
111
123
  end
112
124
 
113
- response = Tumblr.execute(publisher, input)
125
+ post = Tumblr.parse(input)
126
+ post.state = publish_state if publish_state
127
+ post.group = group if group
128
+
129
+ response = Tumblr.execute(publisher, post)
114
130
  if response.success?
115
131
  puts "Published to Tumblr. The ID for this post is: #{response.body}"
116
132
  exit
data/lib/tumblr/post.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  class Tumblr
4
4
  class Post
5
5
  BASIC_PARAMS = [:date,:tags,:format,:group,:generator,:private,
6
- :slug,:state,:'send-to-twitter',:'publish-on']
6
+ :slug,:state,:'send-to-twitter',:'publish-on',:'reblog-key']
7
7
  POST_PARAMS = [:title,:body,:source,:caption,:'click-through-url',
8
8
  :quote,:name,:url,:description,:conversation,
9
9
  :embed,:'externally-hosted-url']
@@ -17,7 +17,7 @@ class Tumblr
17
17
  end
18
18
 
19
19
  attr_reader :type, :state, :post_id, :format
20
- attr_accessor :slug, :date, :group, :generator
20
+ attr_accessor :slug, :date, :group, :generator, :reblog_key
21
21
 
22
22
  def initialize(post_id = nil)
23
23
  @post_id = post_id if post_id
@@ -71,7 +71,7 @@ class Tumblr
71
71
  def to_h
72
72
  post_hash = {}
73
73
  basics = [:post_id, :type, :date, :tags, :format, :group, :generator,
74
- :slug, :state, :send_to_twitter, :publish_on]
74
+ :slug, :state, :send_to_twitter, :publish_on, :reblog_key]
75
75
  params = basics.select {|opt| respond_to?(opt) && send(opt) }
76
76
  params |= self.class.parameters.select {|opt| send(opt) } unless self.class.parameters.blank?
77
77
  params.each { |key| post_hash[key.to_s.gsub('_','-').to_sym] = send(key) } unless params.empty?
@@ -92,6 +92,18 @@ class Tumblr
92
92
  Writer.new(email,password).delete(to_h)
93
93
  end
94
94
 
95
+ def like(email,password)
96
+ if (post_id && reblog_key)
97
+ Reader.new(email,password).like(:'post-id' => post_id, :'reblog-key' => reblog_key)
98
+ end
99
+ end
100
+
101
+ def unlike(email,password)
102
+ if (post_id && reblog_key)
103
+ Reader.new(email,password).unlike(:'post-id' => post_id, :'reblog-key' => reblog_key)
104
+ end
105
+ end
106
+
95
107
  # Write to Tumblr and set state to Publish
96
108
  def publish_now(email, password)
97
109
  self.state = :published
data/lib/tumblr/reader.rb CHANGED
@@ -15,7 +15,7 @@ class Tumblr
15
15
 
16
16
  # http://www.tumblr.com/docs/en/api#authenticated_read
17
17
  def authenticated_read(username, params={})
18
- raise 'Needs requirements badly' unless (params.include?(:email) && params.include?(:password)) || defaults
18
+ raise 'You must provide an email address and password' unless (params.include?(:email) && params.include?(:password)) || defaults
19
19
  self.class.read username, :post, parameters(params)
20
20
  end
21
21
 
@@ -26,6 +26,20 @@ class Tumblr
26
26
  params.reject {|key,value| !allowed.include? key }
27
27
  end
28
28
 
29
+ # Transform ALL of the posts for user/group to Post objects.
30
+ # This could take a while...
31
+ def get_all_posts(username, start = 0, total = nil)
32
+ first_read = authenticated_read(username, {:num => 50,:start => start}).perform
33
+ raise %Q(Tumblr response was not successful, "#{first_read.code}: #{first_read.message}") if !first_read.success?
34
+ posts = self.class.get_posts(first_read)
35
+ offset = start + posts.count
36
+ post_total = total || first_read['tumblr']['posts']['total'].to_i
37
+ if post_total > offset
38
+ posts |= get_all_posts(username, offset, post_total)
39
+ end
40
+ posts
41
+ end
42
+
29
43
  # Get the Posts as Post objects from a Read response.
30
44
  # Pass an additional type parameter to only get Posts of a certain type.
31
45
  def self.get_posts(response, type = nil)
@@ -38,12 +52,13 @@ class Tumblr
38
52
 
39
53
  # Build a Post object from Reader's Post XML
40
54
  def self.build_post(post)
41
- tumblr_post = setup_post(post)
42
- tumblr_post.date = post['date_gmt']
43
- tumblr_post.format = post['format'].to_sym if post['format']
44
- tumblr_post.slug = post['slug']
45
- tumblr_post.tags post['tag'] if post['tag']
46
- tumblr_post
55
+ setup_post(post) do |tumblr_post|
56
+ tumblr_post.date = post['date_gmt']
57
+ tumblr_post.format = post['format'].to_sym if post['format']
58
+ tumblr_post.slug = post['slug']
59
+ tumblr_post.tags post['tag'] if post['tag']
60
+ tumblr_post.reblog_key = post['reblog_key'] if post['reblog_key']
61
+ end
47
62
  end
48
63
 
49
64
  # Helper method to facilitate standard GET Read and Authenticated Read
@@ -83,7 +98,7 @@ class Tumblr
83
98
 
84
99
  def self.setup_post(post)
85
100
  post_type = post['type'].to_sym
86
- case post_type
101
+ tumblr_post = case post_type
87
102
  when :regular
88
103
  build_regular(post)
89
104
  when :photo
@@ -101,6 +116,8 @@ class Tumblr
101
116
  else
102
117
  raise "#{post_type} is not a recognized Tumblr post type."
103
118
  end
119
+ yield tumblr_post if block_given?
120
+ tumblr_post
104
121
  end
105
122
 
106
123
  def self.build_regular(post)
data/lib/tumblr.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'weary'
2
2
 
3
3
  class Tumblr
4
- VERSION = "1.0.0"
4
+ VERSION = "1.1.0"
5
5
  GENERATOR = "The Tumblr Gem v#{VERSION}"
6
6
  USER_AGENT = "TumblrGem/#{VERSION} (+http://github.com/mwunsch/tumblr)"
7
7
 
@@ -54,7 +54,7 @@ class Tumblr
54
54
  Writer.new(@credentials[:email],@credentials[:password])
55
55
  end
56
56
 
57
- def self.execute(credentials, input, state=nil)
57
+ def self.execute(credentials, input)
58
58
  request = new(credentials[:email],credentials[:password]).post(input)
59
59
  request.perform
60
60
  end
@@ -129,8 +129,8 @@ class Tumblr
129
129
  end
130
130
 
131
131
  def self.basic_setup(post, post_data)
132
- %w(format state private slug date group generator).each do |basic|
133
- post.send "#{basic}=".intern, post_data[basic] if post_data[basic]
132
+ %w(format state private slug date group generator reblog-key).each do |basic|
133
+ post.send "#{basic}=".gsub('-','_').intern, post_data[basic] if post_data[basic]
134
134
  end
135
135
  %w(tags send-to-twitter publish-on).each do |attribute|
136
136
  post.send attribute.gsub('-','_').intern, post_data[attribute] if post_data[attribute]
data/man/tumblr.1 CHANGED
@@ -21,16 +21,36 @@ If you preface your \fIFILE\fR with a bit of YAML (<yaml.org>) frontmatter, you
21
21
  .SH "OPTIONS"
22
22
  .
23
23
  .TP
24
- \fB\-a\fR,\fB\-\-auth\fR [\fIEMAIL:PASSWORD\fR]
24
+ \fB\-a\fR,\fB\-\-auth\fR \fIEMAIL:PASSWORD\fR
25
25
  Provide Email Address and Password, to authenticate to Tumblr, separated by a colon.
26
26
  If these are not provided, you will be prompted for them.
27
- You \fBmust\fR provide this argument if the post comes from standard input.
27
+ You \fBmust\fR provide this or the \fB\-\-credentials\fR argument if the post comes from standard input.
28
28
  .
29
29
  .TP
30
- \fB\-e\fR, \fB\-\-email\fR [\fIEMAIL\fR]
30
+ \fB\-e\fR, \fB\-\-email\fR \fIEMAIL\fR
31
31
  Email Address associated with your Tumblr account.
32
32
  You will be prompted for a password.
33
33
  .
34
+ .TP
35
+ \fB\-\-credentials\fR \fIFILE\fR
36
+ A YAML file with the user credentials. Should have keys \fBemail\fR and \fBpassword\fR.
37
+ .
38
+ .TP
39
+ \fB\-p\fR,\fB\-\-publish\fR
40
+ Publish the post immediately. This will ignore the \fBstate\fR parameter set in the post.
41
+ .
42
+ .TP
43
+ \fB\-q\fR,\fB\-\-queue\fR
44
+ Add the post to the queue.
45
+ .
46
+ .TP
47
+ \fB\-d\fR,\fB\-\-draft\fR
48
+ Save the post as a draft.
49
+ .
50
+ .TP
51
+ \fB\-\-group\fR=\fIGROUP\fR
52
+ Publish the post to a \fIGROUP\fR tumblelog.
53
+ .
34
54
  .P
35
55
  Other:
36
56
  .
@@ -90,6 +110,33 @@ $ tumblr http://www.youtube.com/watch?v=CW0DUg63lqU
90
110
  .
91
111
  .IP "" 0
92
112
  .
113
+ .P
114
+ Save it as a draft:
115
+ .
116
+ .IP "" 4
117
+ .
118
+ .nf
119
+ $ tumblr \-d http://www.youtube.com/watch?v=CW0DUg63lqU
120
+ .
121
+ .fi
122
+ .
123
+ .IP "" 0
124
+ .
125
+ .P
126
+ Authenticate with credentials given from a file:
127
+ .
128
+ .IP "" 4
129
+ .
130
+ .nf
131
+ $ cat ~/.tumblrlogin
132
+ email: tumblruser@generic\-email.com
133
+ password: myvoiceismypassport
134
+ $ cat data.yml my_post.txt | tumblr \-\-credentials ~/.tumblrlogin
135
+ .
136
+ .fi
137
+ .
138
+ .IP "" 0
139
+ .
93
140
  .SH "INSTALLATION"
94
141
  If you have RubyGems installed:
95
142
  .
@@ -106,7 +153,7 @@ gem install tumblr\-rb
106
153
  Tumblr (the gem) is Copyright (C) 2010 Mark Wunsch
107
154
  .
108
155
  .P
109
- Tumblr is Copyright (c) Tumblr, Inc. The Tumblr gem is NOT affiliated with Tumblr.
156
+ Tumblr is Copyright (c) Tumblr, Inc. The Tumblr gem is NOT affiliated with Tumblr, Inc.
110
157
  .
111
158
  .SH "SEE ALSO"
112
159
  tumblr(5), gem(1)
data/man/tumblr.1.html CHANGED
@@ -80,11 +80,16 @@
80
80
  <h2>OPTIONS</h2>
81
81
 
82
82
  <dl>
83
- <dt><code>-a</code>,<code>--auth</code> [<em>EMAIL:PASSWORD</em>]</dt><dd><p> Provide Email Address and Password, to authenticate to Tumblr, separated by a colon.
83
+ <dt><code>-a</code>,<code>--auth</code> <em>EMAIL:PASSWORD</em></dt><dd><p> Provide Email Address and Password, to authenticate to Tumblr, separated by a colon.
84
84
  If these are not provided, you will be prompted for them.
85
- You <b>must</b> provide this argument if the post comes from standard input.</p></dd>
86
- <dt><code>-e</code>, <code>--email</code> [<em>EMAIL</em>]</dt><dd><p> Email Address associated with your Tumblr account.
85
+ You <b>must</b> provide this or the <code>--credentials</code> argument if the post comes from standard input.</p></dd>
86
+ <dt><code>-e</code>, <code>--email</code> <em>EMAIL</em></dt><dd><p> Email Address associated with your Tumblr account.
87
87
  You will be prompted for a password.</p></dd>
88
+ <dt><code>--credentials</code> <em>FILE</em></dt><dd><p> A YAML file with the user credentials. Should have keys <code>email</code> and <code>password</code>.</p></dd>
89
+ <dt><code>-p</code>,<code>--publish</code></dt><dd><p> Publish the post immediately. This will ignore the <code>state</code> parameter set in the post.</p></dd>
90
+ <dt><code>-q</code>,<code>--queue</code></dt><dd><p> Add the post to the queue.</p></dd>
91
+ <dt><code>-d</code>,<code>--draft</code></dt><dd><p> Save the post as a draft.</p></dd>
92
+ <dt><code>--group</code>=<em>GROUP</em></dt><dd><p> Publish the post to a <em>GROUP</em> tumblelog.</p></dd>
88
93
  </dl>
89
94
 
90
95
 
@@ -118,6 +123,19 @@
118
123
  <pre><code>$ tumblr http://www.youtube.com/watch?v=CW0DUg63lqU
119
124
  </code></pre>
120
125
 
126
+ <p>Save it as a draft:</p>
127
+
128
+ <pre><code>$ tumblr -d http://www.youtube.com/watch?v=CW0DUg63lqU
129
+ </code></pre>
130
+
131
+ <p>Authenticate with credentials given from a file:</p>
132
+
133
+ <pre><code>$ cat ~/.tumblrlogin
134
+ email: tumblruser@generic-email.com
135
+ password: myvoiceismypassport
136
+ $ cat data.yml my_post.txt | tumblr --credentials ~/.tumblrlogin
137
+ </code></pre>
138
+
121
139
  <h2>INSTALLATION</h2>
122
140
 
123
141
  <p>If you have RubyGems installed:</p>
@@ -129,7 +147,7 @@
129
147
 
130
148
  <p>Tumblr (the gem) is Copyright (C) 2010 Mark Wunsch</p>
131
149
 
132
- <p>Tumblr is Copyright (c) Tumblr, Inc. The Tumblr gem is NOT affiliated with Tumblr.</p>
150
+ <p>Tumblr is Copyright (c) Tumblr, Inc. The Tumblr gem is NOT affiliated with Tumblr, Inc.</p>
133
151
 
134
152
  <h2>SEE ALSO</h2>
135
153
 
data/man/tumblr.1.ronn CHANGED
@@ -15,14 +15,29 @@ If you preface your <FILE> with a bit of YAML (<yaml.org>) frontmatter, you can
15
15
 
16
16
  ## OPTIONS
17
17
 
18
- * `-a`,`--auth` [_EMAIL:PASSWORD_]:
18
+ * `-a`,`--auth` _EMAIL:PASSWORD_:
19
19
  Provide Email Address and Password, to authenticate to Tumblr, separated by a colon.
20
20
  If these are not provided, you will be prompted for them.
21
- You <b>must</b> provide this argument if the post comes from standard input.
21
+ You <b>must</b> provide this or the `--credentials` argument if the post comes from standard input.
22
22
 
23
- * `-e`, `--email` [_EMAIL_]:
23
+ * `-e`, `--email` _EMAIL_:
24
24
  Email Address associated with your Tumblr account.
25
25
  You will be prompted for a password.
26
+
27
+ * `--credentials` _FILE_:
28
+ A YAML file with the user credentials. Should have keys `email` and `password`.
29
+
30
+ * `-p`,`--publish`:
31
+ Publish the post immediately. This will ignore the `state` parameter set in the post.
32
+
33
+ * `-q`,`--queue`:
34
+ Add the post to the queue.
35
+
36
+ * `-d`,`--draft`:
37
+ Save the post as a draft.
38
+
39
+ * `--group`=_GROUP_:
40
+ Publish the post to a _GROUP_ tumblelog.
26
41
 
27
42
  Other:
28
43
 
@@ -50,6 +65,17 @@ Or a Video post:
50
65
 
51
66
  $ tumblr http://www.youtube.com/watch?v=CW0DUg63lqU
52
67
 
68
+ Save it as a draft:
69
+
70
+ $ tumblr -d http://www.youtube.com/watch?v=CW0DUg63lqU
71
+
72
+ Authenticate with credentials given from a file:
73
+
74
+ $ cat ~/.tumblrlogin
75
+ email: tumblruser@generic-email.com
76
+ password: myvoiceismypassport
77
+ $ cat data.yml my_post.txt | tumblr --credentials ~/.tumblrlogin
78
+
53
79
  ## INSTALLATION
54
80
 
55
81
  If you have RubyGems installed:
@@ -60,7 +86,7 @@ If you have RubyGems installed:
60
86
 
61
87
  Tumblr (the gem) is Copyright (C) 2010 Mark Wunsch
62
88
 
63
- Tumblr is Copyright (c) Tumblr, Inc. The Tumblr gem is NOT affiliated with Tumblr.
89
+ Tumblr is Copyright (c) Tumblr, Inc. The Tumblr gem is NOT affiliated with Tumblr, Inc.
64
90
 
65
91
  ## SEE ALSO
66
92
 
@@ -0,0 +1,31 @@
1
+ ---
2
+ - !ruby/struct:VCR::RecordedResponse
3
+ method: :post
4
+ uri: http://www.tumblr.com:80/api/like
5
+ response: !ruby/object:Net::HTTPOK
6
+ body: Liked post 445597771.
7
+ body_exist: true
8
+ code: "200"
9
+ header:
10
+ p3p:
11
+ - CP="ALL ADM DEV PSAi COM OUR OTRo STP IND ONL"
12
+ content-type:
13
+ - text/plain; charset=utf-8
14
+ connection:
15
+ - close
16
+ x-tumblr-usec:
17
+ - D=91330
18
+ server:
19
+ - Apache/2.2.3 (Red Hat)
20
+ date:
21
+ - Sat, 13 Mar 2010 16:30:58 GMT
22
+ content-length:
23
+ - "21"
24
+ x-tumblr-perf:
25
+ - "\"ch:0/ cm:0/ ce:0/ c:0/0 d:0/0 e:0/0\""
26
+ vary:
27
+ - Accept-Encoding
28
+ http_version: "1.1"
29
+ message: OK
30
+ read: true
31
+ socket:
@@ -0,0 +1,42 @@
1
+ ---
2
+ - !ruby/struct:VCR::RecordedResponse
3
+ method: :get
4
+ uri: http://tumblrgemtest.tumblr.com:80/api/read/
5
+ response: !ruby/object:Net::HTTPOK
6
+ body: |
7
+ <?xml version="1.0" encoding="UTF-8"?>
8
+ <tumblr version="1.0"><tumblelog name="tumblrgemtest" timezone="US/Eastern" title="Testing Tumblr Gem"></tumblelog><posts start="0" total="1"><post id="445597771" url="http://tumblrgemtest.tumblr.com/post/445597771" url-with-slug="http://tumblrgemtest.tumblr.com/post/445597771/simple-post-to-check-liking-unliking" type="regular" date-gmt="2010-03-13 16:16:00 GMT" date="Sat, 13 Mar 2010 11:16:00" unix-timestamp="1268496960" format="markdown" reblog-key="DLVWOpfh" slug="simple-post-to-check-liking-unliking"><regular-body>&lt;p&gt;Simple post to check liking/unliking.&lt;/p&gt;</regular-body></post></posts></tumblr>
9
+
10
+ body_exist: true
11
+ code: "200"
12
+ header:
13
+ last-modified:
14
+ - Sat, 13 Mar 2010 16:16:00 GMT
15
+ p3p:
16
+ - CP="ALL ADM DEV PSAi COM OUR OTRo STP IND ONL"
17
+ content-type:
18
+ - text/xml; charset=UTF-8
19
+ connection:
20
+ - close
21
+ x-tumblr-usec:
22
+ - D=270024
23
+ x-robots-tag:
24
+ - noindex
25
+ server:
26
+ - Apache/2.2.3 (CentOS)
27
+ date:
28
+ - Sat, 13 Mar 2010 16:29:06 GMT
29
+ content-length:
30
+ - "660"
31
+ x-cache-auto:
32
+ - miss
33
+ x-tumblr-perf:
34
+ - "\"ch:4/tumblelog_id_for_host,tumblelogs,country_code_for_ip,tumblelog_post_count cm:4/rate-limiter,rate-limiter,rate-limiter,auto ce:0/ c:0/0 d:0/0 e:0/0\""
35
+ vary:
36
+ - Accept-Encoding
37
+ cache-control:
38
+ - max-age=900
39
+ http_version: "1.1"
40
+ message: OK
41
+ read: true
42
+ socket:
@@ -0,0 +1,31 @@
1
+ ---
2
+ - !ruby/struct:VCR::RecordedResponse
3
+ method: :post
4
+ uri: http://www.tumblr.com:80/api/unlike
5
+ response: !ruby/object:Net::HTTPOK
6
+ body: Unliked post 445597771.
7
+ body_exist: true
8
+ code: "200"
9
+ header:
10
+ p3p:
11
+ - CP="ALL ADM DEV PSAi COM OUR OTRo STP IND ONL"
12
+ content-type:
13
+ - text/plain; charset=utf-8
14
+ connection:
15
+ - close
16
+ x-tumblr-usec:
17
+ - D=119300
18
+ server:
19
+ - Apache/2.2.3 (Red Hat)
20
+ date:
21
+ - Sat, 13 Mar 2010 16:33:13 GMT
22
+ content-length:
23
+ - "23"
24
+ x-tumblr-perf:
25
+ - "\"ch:0/ cm:0/ ce:0/ c:0/0 d:0/0 e:0/0\""
26
+ vary:
27
+ - Accept-Encoding
28
+ http_version: "1.1"
29
+ message: OK
30
+ read: true
31
+ socket:
data/test/test_tumblr.rb CHANGED
@@ -200,6 +200,18 @@ link
200
200
  assert_respond_to reader, :like
201
201
  assert_respond_to reader, :unlike
202
202
  end
203
+
204
+ test 'likes a post' do
205
+ reader = Tumblr::Reader.new('test@testermcgee.com','dontrevealmysecrets')
206
+ like = hijack! reader.like(:'post-id' => '445597771', :'reblog-key' => 'DLVWOpfh'), 'read/like'
207
+ assert like.success?
208
+ end
209
+
210
+ test 'unlikes a post' do
211
+ reader = Tumblr::Reader.new('test@testermcgee.com','dontrevealmysecrets')
212
+ unlike = hijack! reader.unlike(:'post-id' => '445597771', :'reblog-key' => 'DLVWOpfh'), 'read/unlike'
213
+ assert unlike.success?
214
+ end
203
215
 
204
216
  test 'parses posts out of a read' do
205
217
  reader = Tumblr::Reader
@@ -230,6 +242,15 @@ link
230
242
  assert_equal :link, link_post.type
231
243
  assert_equal :markdown, link_post.format
232
244
  assert_equal link.first['link_url'], link_post.url
245
+ assert_equal link.first['reblog_key'], link_post.reblog_key
246
+ end
247
+
248
+ test 'gets all the posts for a username' do
249
+ reader = Tumblr::Reader.new('test@testermcgee.com','dontrevealmysecrets')
250
+ posts = VCR.with_cassette('read/authenticated') do
251
+ reader.get_all_posts('mwunsch')
252
+ end
253
+ assert_equal 66, posts.count
233
254
  end
234
255
  end
235
256
 
@@ -287,7 +308,7 @@ link
287
308
  end
288
309
  end
289
310
 
290
- describe 'Post' do
311
+ describe 'Post' do
291
312
  describe 'Basic' do
292
313
  test 'has a set of post-specific parameters' do
293
314
  klass = Class.new(Tumblr::Post)
@@ -323,6 +344,13 @@ link
323
344
  assert post.private?
324
345
  end
325
346
 
347
+ test 'can have a reblog key' do
348
+ post = Tumblr::Post.new
349
+ assert_respond_to post, :reblog_key
350
+ post.reblog_key = 'reblog_me'
351
+ assert_equal 'reblog_me', post.reblog_key
352
+ end
353
+
326
354
  test 'has a comma separated list of tags' do
327
355
  post = Tumblr::Post.new
328
356
  assert_respond_to post, :tags
@@ -414,6 +442,22 @@ link
414
442
  post = Tumblr::Post.new(123)
415
443
  assert post.delete('test@testermcgee.com','dontrevealmysecrets').is_a? Weary::Request
416
444
  end
445
+
446
+ test 'likes itself' do
447
+ post = Tumblr::Post.new(445597771)
448
+ post.reblog_key = "DLVWOpfh"
449
+ like = post.like('test@testermcgee.com','dontrevealmysecrets')
450
+ assert like.is_a? Weary::Request
451
+ assert_equal 'http://www.tumblr.com/api/like', like.uri.to_s
452
+ end
453
+
454
+ test 'unlikes itself' do
455
+ post = Tumblr::Post.new(445597771)
456
+ post.reblog_key = "DLVWOpfh"
457
+ unlike = post.unlike('test@testermcgee.com','dontrevealmysecrets')
458
+ assert unlike.is_a? Weary::Request
459
+ assert_equal 'http://www.tumblr.com/api/unlike', unlike.uri.to_s
460
+ end
417
461
 
418
462
  test 'publishes to tumblr' do
419
463
  klass = Class.new Tumblr::Post
data/tumblr-rb.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{tumblr-rb}
8
- s.version = "1.0.0"
8
+ s.version = "1.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Mark Wunsch"]
12
- s.date = %q{2010-03-10}
12
+ s.date = %q{2010-03-14}
13
13
  s.default_executable = %q{tumblr}
14
14
  s.description = %q{Ruby library and command line utility to work with the Tumblr Blogging Platform, powered by Weary.}
15
15
  s.email = %q{mark@markwunsch.com}
@@ -47,8 +47,11 @@ Gem::Specification.new do |s|
47
47
  "test/fixtures/vcr_cassettes/authenticate/authenticate.yml",
48
48
  "test/fixtures/vcr_cassettes/read/authenticated.yml",
49
49
  "test/fixtures/vcr_cassettes/read/authentication_failure.yml",
50
+ "test/fixtures/vcr_cassettes/read/like.yml",
50
51
  "test/fixtures/vcr_cassettes/read/mwunsch.yml",
51
52
  "test/fixtures/vcr_cassettes/read/optional.yml",
53
+ "test/fixtures/vcr_cassettes/read/tumblrgemtest.yml",
54
+ "test/fixtures/vcr_cassettes/read/unlike.yml",
52
55
  "test/fixtures/vcr_cassettes/write/delete.yml",
53
56
  "test/fixtures/vcr_cassettes/write/edit.yml",
54
57
  "test/fixtures/vcr_cassettes/write/write.yml",
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 1
7
+ - 1
7
8
  - 0
8
- - 0
9
- version: 1.0.0
9
+ version: 1.1.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Mark Wunsch
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-10 00:00:00 -05:00
17
+ date: 2010-03-14 00:00:00 -05:00
18
18
  default_executable: tumblr
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -97,8 +97,11 @@ files:
97
97
  - test/fixtures/vcr_cassettes/authenticate/authenticate.yml
98
98
  - test/fixtures/vcr_cassettes/read/authenticated.yml
99
99
  - test/fixtures/vcr_cassettes/read/authentication_failure.yml
100
+ - test/fixtures/vcr_cassettes/read/like.yml
100
101
  - test/fixtures/vcr_cassettes/read/mwunsch.yml
101
102
  - test/fixtures/vcr_cassettes/read/optional.yml
103
+ - test/fixtures/vcr_cassettes/read/tumblrgemtest.yml
104
+ - test/fixtures/vcr_cassettes/read/unlike.yml
102
105
  - test/fixtures/vcr_cassettes/write/delete.yml
103
106
  - test/fixtures/vcr_cassettes/write/edit.yml
104
107
  - test/fixtures/vcr_cassettes/write/write.yml