tumblr-rb 1.3.0 → 2.0.0.alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. data/.travis.yml +7 -0
  2. data/Gemfile +15 -8
  3. data/Gemfile.lock +65 -65
  4. data/LICENSE +4 -2
  5. data/README.md +31 -84
  6. data/Rakefile +8 -68
  7. data/bin/tumblr +3 -133
  8. data/lib/tumblr.rb +7 -184
  9. data/lib/tumblr/authentication.rb +71 -0
  10. data/lib/tumblr/client.rb +148 -0
  11. data/lib/tumblr/command_line_interface.rb +222 -0
  12. data/lib/tumblr/credentials.rb +31 -0
  13. data/lib/tumblr/post.rb +253 -171
  14. data/lib/tumblr/post/answer.rb +17 -0
  15. data/lib/tumblr/post/audio.rb +22 -10
  16. data/lib/tumblr/post/chat.rb +25 -0
  17. data/lib/tumblr/post/link.rb +22 -9
  18. data/lib/tumblr/post/photo.rb +29 -10
  19. data/lib/tumblr/post/quote.rb +17 -10
  20. data/lib/tumblr/post/text.rb +18 -0
  21. data/lib/tumblr/post/video.rb +26 -11
  22. data/lib/tumblr/version.rb +3 -0
  23. data/lib/tumblr/views/error.erb +6 -0
  24. data/lib/tumblr/views/form.erb +11 -0
  25. data/lib/tumblr/views/layout.erb +41 -0
  26. data/lib/tumblr/views/success.erb +6 -0
  27. data/man/tumblr.1 +67 -65
  28. data/man/tumblr.1.html +131 -108
  29. data/man/tumblr.1.ronn +76 -57
  30. data/man/tumblr.5 +48 -68
  31. data/man/tumblr.5.html +106 -114
  32. data/man/tumblr.5.ronn +38 -51
  33. data/spec/fixtures/posts.json +10 -0
  34. data/spec/fixtures/typical_animated_gif.gif +0 -0
  35. data/spec/spec_helper.rb +12 -0
  36. data/spec/tumblr/authentication_spec.rb +57 -0
  37. data/spec/tumblr/client_spec.rb +223 -0
  38. data/spec/tumblr/credentials_spec.rb +63 -0
  39. data/spec/tumblr/post_spec.rb +125 -0
  40. data/tumblr-rb.gemspec +16 -89
  41. metadata +101 -102
  42. data/lib/tumblr/authenticator.rb +0 -18
  43. data/lib/tumblr/post/conversation.rb +0 -15
  44. data/lib/tumblr/post/regular.rb +0 -14
  45. data/lib/tumblr/reader.rb +0 -191
  46. data/lib/tumblr/writer.rb +0 -39
  47. data/test/fixtures/vcr_cassettes/authenticate/authenticate.yml +0 -39
  48. data/test/fixtures/vcr_cassettes/read/all_pages.yml +0 -34
  49. data/test/fixtures/vcr_cassettes/read/authenticated.yml +0 -40
  50. data/test/fixtures/vcr_cassettes/read/authentication_failure.yml +0 -33
  51. data/test/fixtures/vcr_cassettes/read/like.yml +0 -31
  52. data/test/fixtures/vcr_cassettes/read/mwunsch.yml +0 -101
  53. data/test/fixtures/vcr_cassettes/read/optional.yml +0 -48
  54. data/test/fixtures/vcr_cassettes/read/pages.yml +0 -36
  55. data/test/fixtures/vcr_cassettes/read/tumblrgemtest.yml +0 -42
  56. data/test/fixtures/vcr_cassettes/read/unlike.yml +0 -31
  57. data/test/fixtures/vcr_cassettes/write/delete.yml +0 -31
  58. data/test/fixtures/vcr_cassettes/write/edit.yml +0 -31
  59. data/test/fixtures/vcr_cassettes/write/reblog.yml +0 -31
  60. data/test/fixtures/vcr_cassettes/write/write.yml +0 -31
  61. data/test/helper.rb +0 -44
  62. data/test/test_tumblr.rb +0 -710
@@ -0,0 +1,17 @@
1
+ module Tumblr
2
+ class Post
3
+ class Answer < Post
4
+ def initialize(post_data = {})
5
+ super(post_data)
6
+ @type = :answer
7
+ end
8
+
9
+ def answer
10
+ @answer
11
+ end
12
+ end
13
+ end
14
+ end
15
+
16
+
17
+
@@ -1,16 +1,28 @@
1
- #TODO: Support File uploading
2
-
3
- class Tumblr
1
+ module Tumblr
4
2
  class Post
5
3
  class Audio < Post
6
-
7
- def initialize(post_id = nil)
8
- super post_id
4
+ def initialize(post_data = {})
5
+ super(post_data)
9
6
  @type = :audio
10
7
  end
11
-
12
- parameters :externally_hosted_url, :caption
13
-
8
+
9
+ def caption
10
+ @caption
11
+ end
12
+
13
+ def external_url
14
+ @external_url
15
+ end
16
+
17
+ def data
18
+ @data
19
+ end
20
+
21
+ def self.post_body_keys
22
+ [:external_url, :caption]
23
+ end
14
24
  end
15
25
  end
16
- end
26
+ end
27
+
28
+
@@ -0,0 +1,25 @@
1
+ module Tumblr
2
+ class Post
3
+ class Chat < Post
4
+ def initialize(post_data = {})
5
+ super(post_data)
6
+ @type = :chat
7
+ end
8
+
9
+ def title
10
+ @title
11
+ end
12
+
13
+ def conversation
14
+ @conversation
15
+ end
16
+
17
+ def self.post_body_keys
18
+ [:conversation]
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+
25
+
@@ -1,15 +1,28 @@
1
- class Tumblr
1
+ module Tumblr
2
2
  class Post
3
3
  class Link < Post
4
-
5
- def initialize(url, post_id = nil)
6
- super post_id
7
- self.url = url
4
+ def initialize(post_data = {})
5
+ super(post_data)
8
6
  @type = :link
9
7
  end
10
-
11
- parameters :url, :name, :description
12
-
8
+
9
+ def title
10
+ @title
11
+ end
12
+
13
+ def url
14
+ @url
15
+ end
16
+
17
+ def description
18
+ @description
19
+ end
20
+
21
+ def self.post_body_keys
22
+ [:url, :description]
23
+ end
13
24
  end
14
25
  end
15
- end
26
+ end
27
+
28
+
@@ -1,16 +1,35 @@
1
- #TODO: Support file uploads
2
-
3
- class Tumblr
1
+ module Tumblr
4
2
  class Post
5
3
  class Photo < Post
6
-
7
- def initialize(post_id = nil)
8
- super post_id
4
+ def initialize(post_data = {})
5
+ super(post_data)
9
6
  @type = :photo
7
+ @source ||= first_photo_url_from_response
8
+ end
9
+
10
+ def caption
11
+ @caption
12
+ end
13
+
14
+ def link
15
+ @link
16
+ end
17
+
18
+ def source
19
+ @source
20
+ end
21
+
22
+ def data
23
+ @data
24
+ end
25
+
26
+ def first_photo_url_from_response
27
+ @photos.first["original_size"]["url"] if @photos and !@photos.empty?
28
+ end
29
+
30
+ def self.post_body_keys
31
+ [:source, :caption]
10
32
  end
11
-
12
- parameters :source, :caption, :click_through_url
13
-
14
33
  end
15
34
  end
16
- end
35
+ end
@@ -1,16 +1,23 @@
1
- class Tumblr
1
+ module Tumblr
2
2
  class Post
3
3
  class Quote < Post
4
-
5
- def initialize(quotation, post_id = nil)
6
- super post_id
7
- self.quote = quotation
4
+ def initialize(post_data = {})
5
+ super(post_data)
8
6
  @type = :quote
9
7
  end
10
-
11
- parameters :quote, :source
12
-
13
-
8
+
9
+ def quote
10
+ @quote
11
+ end
12
+
13
+ def source
14
+ @source
15
+ end
16
+
17
+ def self.post_body_keys
18
+ [:quote]
19
+ end
14
20
  end
15
21
  end
16
- end
22
+ end
23
+
@@ -0,0 +1,18 @@
1
+ module Tumblr
2
+ class Post
3
+ class Text < Post
4
+ def initialize(post_data = {})
5
+ super(post_data)
6
+ @type = :text
7
+ end
8
+
9
+ def body
10
+ @body
11
+ end
12
+
13
+ def title
14
+ @title
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,17 +1,32 @@
1
- #TODO: Support file uploading
2
-
3
- class Tumblr
1
+ module Tumblr
4
2
  class Post
5
3
  class Video < Post
6
-
7
- def initialize(video, post_id = nil)
8
- super post_id
9
- self.embed = video
4
+ def initialize(post_data = {})
5
+ super(post_data)
10
6
  @type = :video
7
+ @embed ||= get_embed_code_from_response
8
+ end
9
+
10
+ def caption
11
+ @caption
12
+ end
13
+
14
+ def embed
15
+ @embed
16
+ end
17
+
18
+ def data
19
+ @data
20
+ end
21
+
22
+ def get_embed_code_from_response
23
+ @player.last["embed_code"] if @player and !@player.empty?
24
+ end
25
+
26
+ def self.post_body_keys
27
+ [:embed, :caption]
11
28
  end
12
-
13
- parameters :caption, :embed
14
-
15
29
  end
16
30
  end
17
- end
31
+ end
32
+
@@ -0,0 +1,3 @@
1
+ module Tumblr
2
+ VERSION = "2.0.0.alpha"
3
+ end
@@ -0,0 +1,6 @@
1
+ <p>
2
+ It would appear the user denied access, or there was an error.
3
+ </p>
4
+ <p>
5
+ You can try to <a href="/">authenticate again</a> or return to the terminal in defeat and <span class="command">`Ctrl-C`</span>.
6
+ </p>
@@ -0,0 +1,11 @@
1
+ <form class="auth" action="/">
2
+ <label class="key">Consumer Key: <input name="key" /></label>
3
+ <label class="secret">Consumer Secret: <input name="secret" /></label>
4
+ <input type="submit" />
5
+ </form>
6
+ <p>
7
+ You need to <a href="http://www.tumblr.com/oauth/apps" target="_blank">register for an application on Tumblr</a>, then put your <em>consumer</em> key and secret here.
8
+ </p>
9
+ <p>
10
+ You will then be redirected to Tumblr to authenticate and authorize.
11
+ </p>
@@ -0,0 +1,41 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Authenticate and Authorize</title>
5
+ <style type="text/css">
6
+ body {
7
+ color: rgb(40, 254, 20);
8
+ font-size: 14px;
9
+ font-family: Consolas, Menlo, Monaco, monospace;
10
+ background: #191919;
11
+ }
12
+ .main {
13
+ width: 640px;
14
+ margin: 0 auto;
15
+ }
16
+ .tumblr-logo {
17
+ font-family: Consolas, Menlo, Monaco, monospace;
18
+ }
19
+ a, .command {
20
+ color: #94ff8a;
21
+ }
22
+ .command {
23
+ font-weight: bold;
24
+ }
25
+ </style>
26
+ </head>
27
+ <body>
28
+ <div class="main">
29
+ <pre class="tumblr-logo">
30
+ . .o8 oooo
31
+ .o8 "888 `888
32
+ .o888oo oooo oooo ooo. .oo. .oo. 888oooo. 888 oooo d8b
33
+ 888 `888 `888 `888P"Y88bP"Y88b d88' `88b 888 `888""8P
34
+ 888 888 888 888 888 888 888 888 888 888
35
+ 888 . 888 888 888 888 888 888 888 888 888 .o.
36
+ "888" `V88V"V8P' o888o o888o o888o `Y8bod8P' o888o d888b Y8P
37
+ </pre>
38
+ <%= yield %>
39
+ </div>
40
+ </body>
41
+ </html>
@@ -0,0 +1,6 @@
1
+ <p>
2
+ Success! Your credentials were saved to <span class="command"><%= @credential_path %>
3
+ </p>
4
+ <p>
5
+ Now return to your terminal and shut down this application by typing <span class="command">Ctrl-C</span> (<em>SIGINT</em>).
6
+ </p>
@@ -1,159 +1,161 @@
1
- .\" generated with Ronn/v0.4.1
2
- .\" http://github.com/rtomayko/ronn/
1
+ .\" generated with Ronn/v0.7.3
2
+ .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "TUMBLR" "1" "March 2010" "Mark Wunsch" "Tumblr Manual"
4
+ .TH "TUMBLR" "1" "October 2012" "Mark Wunsch" "Tumblr Manual"
5
5
  .
6
6
  .SH "NAME"
7
- \fBtumblr\fR \-\- publish to tumblr.com
7
+ \fBtumblr\fR \- publish to tumblr\.com
8
8
  .
9
9
  .SH "SYNOPSIS"
10
- \fBtumblr\fR [\fIOPTIONS\fR] \fIFILE OR URL\fR
10
+ \fBtumblr\fR COMMAND [ARGS]
11
11
  .
12
12
  .SH "DESCRIPTION"
13
- \fBtumblr\fR is a command line utility and Ruby library for working with Tumblr.com. It can read plain\-text files and publish them to Tumblr.
13
+ \fBtumblr\fR is a command line utility and Ruby library for working with Tumblr\.com\. It can read plain\-text and binary files and publish them to Tumblr\.
14
14
  .
15
15
  .P
16
- The \fBtumblr\fR command will publish a named input \fIFILE\fR (or Standard Input if no file is given), or if a \fIURL\fR is given it will publish that URL as a Link post (or a Video post if the url is a YouTube or Vimeo post).
16
+ \fBtumblr\fR is driven through a group of \fICOMMANDS\fR (similar to \fBgit\fR or \fBrbenv\fR)\.
17
17
  .
18
18
  .P
19
- If you preface your \fIFILE\fR with a bit of YAML (<yaml.org>) frontmatter, you can give \fBtumblr\fR more explicit instructions for publishing your post. See tumblr(5) for available YAML parameters.
19
+ If you preface your plaintext file with a bit of YAML (<yaml\.org>) frontmatter, you can give \fBtumblr\fR more explicit instructions for how to publish your post\. See tumblr(5) for available YAML parameters\.
20
20
  .
21
- .SH "OPTIONS"
21
+ .SH "COMMANDS"
22
22
  .
23
23
  .TP
24
- \fB\-a\fR,\fB\-\-auth\fR \fIEMAIL:PASSWORD\fR
25
- Provide Email Address and Password, to authenticate to Tumblr, separated by a colon.
26
- If these are not provided, you will be prompted for them.
27
- You \fBmust\fR provide this or the \fB\-\-credentials\fR argument if the post comes from standard input.
24
+ \fBtumblr post\fR \fIPOST\fR | \fIFILE\fR | \fIURL\fR
25
+ Post to tumblr\. A \fIPOST\fR is a piece of plaintext, assumed to be formatted as \fBtumblr(5)\fR\. \fIFILE\fR is a path to a \fIPOST\fR\. If \fIFILE\fR has a binary extension, that file will be uploaded as an image, audio, or video post\. \fIURL\fR will create a link\-type post, or a video or audio post, depending on the location of the url\.
28
26
  .
29
27
  .TP
30
- \fB\-e\fR, \fB\-\-email\fR \fIEMAIL\fR
31
- Email Address associated with your Tumblr account.
32
- You will be prompted for a password.
28
+ \fBtumblr pipe\fR
29
+ Read from STDIN and post to tumblr\.
33
30
  .
34
31
  .TP
35
- \fB\-\-credentials\fR \fIFILE\fR
36
- A YAML file with the user credentials. Should have keys \fBemail\fR and \fBpassword\fR.
32
+ \fBtumblr edit\fR \fIPOST_ID\fR
33
+ Edit \fIPOST_ID\fR on tumblr\. Will open the serialized post in the foreground with $TUMBLREDITOR then $EDITOR\.
37
34
  .
38
35
  .TP
39
- \fB\-p\fR,\fB\-\-publish\fR
40
- Publish the post immediately. This will ignore the \fBstate\fR parameter set in the post.
36
+ \fBtumblr fetch\fR \fIPOST_ID\fR
37
+ Fetch \fIPOST_ID\fR from tumblr and write out its serialized form\.
41
38
  .
42
39
  .TP
43
- \fB\-q\fR,\fB\-\-queue\fR
44
- Add the post to the queue.
40
+ \fBtumblr delete\fR \fIPOST_ID\fR
41
+ Delete \fIPOST_ID\fR from tumblr\.
45
42
  .
46
43
  .TP
47
- \fB\-d\fR,\fB\-\-draft\fR
48
- Save the post as a draft.
44
+ \fBtumblr help\fR [\fITASK\fR]
45
+ Print the help message and the description for \fITASK\fR\.
49
46
  .
50
47
  .TP
51
- \fB\-\-group\fR=\fIGROUP\fR
52
- Publish the post to a \fIGROUP\fR tumblelog.
48
+ \fBtumblr authorize\fR
49
+ Start a web server and application to authenticate to tumblr and authorize the cli\. See \fIAUTHORIZATION\fR
53
50
  .
54
- .P
55
- Other:
51
+ .TP
52
+ \fBtumblr version\fR
53
+ Print the \fBtumblr\fR version and quit\.
54
+ .
55
+ .SH "POSTING OPTIONS"
56
+ These options are used when posting to tumblr, i\.e\. when using \fBtumblr post\fR or \fBtumblr pipe\fR\.
56
57
  .
57
58
  .TP
58
- \fB\-h\fR, \fB\-\-help\fR
59
- Print the help message and quit.
59
+ \fB\-p\fR,\fB\-\-publish\fR
60
+ Publish this post (ignoring the \fBstate\fR parameter set in the post)\.
60
61
  .
61
62
  .TP
62
- \fB\-v\fR, \fB\-\-version\fR
63
- Print the \fBtumblr\fR version and quit.
63
+ \fB\-q\fR,\fB\-\-queue\fR
64
+ Add this post to the queue\.
64
65
  .
65
- .SH "EXAMPLES"
66
- Publish a file to Tumblr.com:
66
+ .TP
67
+ \fB\-d\fR,\fB\-\-draft\fR
68
+ Save this post as a draft\.
67
69
  .
68
- .IP "" 4
70
+ .SH "COMMON OPTIONS"
69
71
  .
70
- .nf
71
- $ tumblr my_post.txt
72
+ .TP
73
+ \fB\-\-credentials\fR=\fIPATH\fR
74
+ The file where your OAuth keys are stored\. When authenticating, this path is where the keys should be stored\.
72
75
  .
73
- .fi
76
+ .TP
77
+ \fB\-\-host\fR=\fIHOST\fR
78
+ The hostname of the Tumblr account your posting to\. Posting and fetching posts require the hostname\.
74
79
  .
75
- .IP "" 0
80
+ .SH "AUTHORIZATION"
81
+ Most actions of the cli require authorization to Tumblr\. \fBtumblr authorize\fR provides a mechanism to authenticate and authorize the cli\.
76
82
  .
77
83
  .P
78
- Or from standard input:
79
- .
80
- .IP "" 4
81
- .
82
- .nf
83
- $ cat data.yml my_post.txt | tumblr \-a tumblr_user@foobar.com:p4ssw0rd
84
- .
85
- .fi
86
- .
87
- .IP "" 0
84
+ In order to use \fBtumblr\fR, you first need to register \fIhttp://www\.tumblr\.com/oauth/apps\fR an OAuth application with tumblr\.
88
85
  .
89
86
  .P
90
- Make a Link post:
87
+ Run \fBtumblr authorize\fR to start up server, and type in the consumer key and secret\. You\'ll then be asked to authorize the app\. These keys are saved to the file noted in \fB\-\-credentials\fR, defaulting to \fB~/\.tumblr\fR\. If you choose not to use this default, you will need to enter the \fB\-\-credentials\fR option every time you post\. Alternatively, use the \fB$TUMBLRCRED\fR environment variable\.
88
+ .
89
+ .SH "EXAMPLES"
90
+ Publish a file to Tumblr\.com:
91
91
  .
92
92
  .IP "" 4
93
93
  .
94
94
  .nf
95
- $ tumblr http://github.com/mwunsch/tumblr
95
+
96
+ $ tumblr post my_post\.txt
96
97
  .
97
98
  .fi
98
99
  .
99
100
  .IP "" 0
100
101
  .
101
102
  .P
102
- Or a Video post:
103
+ Or from standard input:
103
104
  .
104
105
  .IP "" 4
105
106
  .
106
107
  .nf
107
- $ tumblr http://www.youtube.com/watch?v=CW0DUg63lqU
108
+
109
+ $ cat data\.yml my_post\.txt | tumblr \-\-host=mwunsch\.tumblr\.com
108
110
  .
109
111
  .fi
110
112
  .
111
113
  .IP "" 0
112
114
  .
113
115
  .P
114
- Save it as a draft:
116
+ Make a Link post:
115
117
  .
116
118
  .IP "" 4
117
119
  .
118
120
  .nf
119
- $ tumblr \-d http://www.youtube.com/watch?v=CW0DUg63lqU
121
+
122
+ $ tumblr post http://github\.com/mwunsch/tumblr
120
123
  .
121
124
  .fi
122
125
  .
123
126
  .IP "" 0
124
127
  .
125
128
  .P
126
- Authenticate with credentials given from a file:
129
+ Or a Video post:
127
130
  .
128
131
  .IP "" 4
129
132
  .
130
133
  .nf
131
- $ cat ~/.tumblrlogin
132
- email: tumblruser@generic\-email.com
133
- password: myvoiceismypassport
134
- $ cat data.yml my_post.txt | tumblr \-\-credentials ~/.tumblrlogin
134
+
135
+ $ tumblr post http://www\.youtube\.com/watch?v=CW0DUg63lqU
135
136
  .
136
137
  .fi
137
138
  .
138
139
  .IP "" 0
139
140
  .
140
- .SH "INSTALLATION"
141
- If you have RubyGems installed:
141
+ .P
142
+ Save it as a draft:
142
143
  .
143
144
  .IP "" 4
144
145
  .
145
146
  .nf
146
- gem install tumblr\-rb
147
+
148
+ $ tumblr post \-d http://www\.youtube\.com/watch?v=CW0DUg63lqU
147
149
  .
148
150
  .fi
149
151
  .
150
152
  .IP "" 0
151
153
  .
152
154
  .SH "COPYRIGHT"
153
- Tumblr (the gem) is Copyright (C) 2010 Mark Wunsch
155
+ Tumblr (the gem) is Copyright (C) 2010 \- 2012 Mark Wunsch
154
156
  .
155
157
  .P
156
- Tumblr is Copyright (c) Tumblr, Inc. The Tumblr gem is NOT affiliated with Tumblr, Inc.
158
+ Tumblr is Copyright (c) Tumblr, Inc\. The Tumblr gem is NOT affiliated with Tumblr, Inc\.
157
159
  .
158
160
  .SH "SEE ALSO"
159
161
  tumblr(5), gem(1)