cloudapp 2.0.0.beta.4 → 2.0.0.beta.5

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.
Files changed (50) hide show
  1. data/Gemfile.lock +12 -19
  2. data/README.md +60 -6
  3. data/Rakefile +1 -19
  4. data/bin/cloudapp +48 -0
  5. data/cloudapp.gemspec +11 -42
  6. data/lib/cloudapp/authorized.rb +14 -0
  7. data/lib/cloudapp/collection_json.rb +86 -3
  8. data/lib/cloudapp/credentials.rb +115 -0
  9. data/lib/cloudapp/service.rb +43 -146
  10. data/lib/cloudapp.rb +1 -3
  11. data/man/cloudapp.1 +100 -0
  12. data/man/cloudapp.1.html +157 -0
  13. data/man/cloudapp.1.ronn +56 -0
  14. metadata +24 -69
  15. data/CHANGELOG.md +0 -34
  16. data/lib/cloudapp/authorized_representation.rb +0 -17
  17. data/lib/cloudapp/collection_json/item.rb +0 -20
  18. data/lib/cloudapp/collection_json/representation.rb +0 -74
  19. data/lib/cloudapp/collection_json/template.rb +0 -17
  20. data/lib/cloudapp/collection_json/tint.rb +0 -11
  21. data/lib/cloudapp/drop.rb +0 -37
  22. data/lib/cloudapp/drop_collection.rb +0 -37
  23. data/spec/cassettes/account_token.yml +0 -88
  24. data/spec/cassettes/create_bookmark.yml +0 -132
  25. data/spec/cassettes/create_bookmark_with_name.yml +0 -133
  26. data/spec/cassettes/create_bookmark_with_privacy.yml +0 -133
  27. data/spec/cassettes/list_drops.yml +0 -87
  28. data/spec/cassettes/list_drops_with_bad_token.yml +0 -45
  29. data/spec/cassettes/list_drops_with_filter.yml +0 -129
  30. data/spec/cassettes/list_drops_with_limit.yml +0 -129
  31. data/spec/cassettes/purge_drops.yml +0 -466
  32. data/spec/cassettes/setup_drops.yml +0 -620
  33. data/spec/cassettes/token_for_account.yml +0 -88
  34. data/spec/cassettes/token_for_account_with_bad_credentials.yml +0 -86
  35. data/spec/cassettes/upload_file.yml +0 -276
  36. data/spec/cassettes/upload_file_with_name.yml +0 -278
  37. data/spec/cassettes/upload_file_with_privacy.yml +0 -277
  38. data/spec/cassettes/view_drop.yml +0 -45
  39. data/spec/cloudapp/authorized_representation_spec.rb +0 -32
  40. data/spec/cloudapp/collection_json/item_spec.rb +0 -45
  41. data/spec/cloudapp/collection_json/representation_spec.rb +0 -118
  42. data/spec/cloudapp/collection_json/template_spec.rb +0 -53
  43. data/spec/cloudapp/drop_collection_spec.rb +0 -127
  44. data/spec/cloudapp/drop_spec.rb +0 -142
  45. data/spec/cloudapp/service_spec.rb +0 -335
  46. data/spec/helper.rb +0 -8
  47. data/spec/integration_spec.rb +0 -68
  48. data/spec/support/files/favicon.ico +0 -0
  49. data/spec/support/stub_class_or_module.rb +0 -22
  50. data/spec/support/vcr.rb +0 -24
@@ -1,17 +1,14 @@
1
1
  require 'leadlight'
2
- require 'typhoeus'
3
- require 'cloudapp/authorized_representation'
2
+ require 'cloudapp/authorized'
4
3
  require 'cloudapp/collection_json'
5
- require 'cloudapp/collection_json/tint'
6
- require 'cloudapp/drop'
7
- require 'cloudapp/drop_collection'
4
+ require 'uri'
8
5
 
9
6
  module CloudApp
10
7
  class Service
11
- Leadlight.build_service(self) do
12
- url 'https://api.getcloudapp.com'
13
- tints << CollectionJson::Tint
14
- tints << AuthorizedRepresentation::Tint
8
+ Leadlight.build_service self do
9
+ url 'http://api.getcloudapp.com'
10
+ tints << CloudApp::CollectionJson::Tint
11
+ tints << CloudApp::Authorized::Tint
15
12
 
16
13
  build_connection do |c|
17
14
  c.adapter :typhoeus
@@ -20,173 +17,73 @@ module CloudApp
20
17
 
21
18
  def initialize
22
19
  super
23
- # logger.level = Logger::INFO
24
20
  logger.level = Logger::WARN
25
21
  end
26
22
 
27
- def token=(token)
28
- connection.token_auth token
29
- end
30
-
31
- def self.using_token(token)
32
- new.tap do |service|
33
- service.token = token
34
- end
35
- end
36
-
37
- def self.token_for_account(email, password)
38
- representation = new.account_token email, password
39
- return if representation.unauthorized?
40
-
41
- representation.items.first.data['token']
42
- end
43
-
44
- def account_token(email, password)
45
- authenticate_response = root
46
- data = authenticate_response.template.
47
- fill('email' => email, 'password' => password)
48
-
49
- post(authenticate_response.href, data) do |response|
50
- return response
51
- end
23
+ def self.using_token token
24
+ service = new
25
+ service.token = token
26
+ service
52
27
  end
53
28
 
54
- def drops(params = {})
55
- params = params.each_with_object({}) {|(key, value), params|
56
- params[key.to_s] = value
57
- }
58
-
59
- get('/') do |response|
60
- return DropCollection.new(response, self) if response.unauthorized?
61
-
62
- drops = response.link('drops').follow
63
- return DropCollection.new(drops, self) if params.empty?
64
-
65
- drops_query = drops.query 'drops-list'
66
- href = Addressable::URI.parse drops_query.href
67
- href.query_values = drops_query.fill params
68
-
69
- get(href) do |response| return DropCollection.new(response, self) end
70
- end
29
+ def token= token
30
+ connection.token_auth token
71
31
  end
72
32
 
73
- def drop(href)
74
- DropCollection.new drops_at(href), self
33
+ def self.token_for_account email, password
34
+ new.token_for_account(email, password)
75
35
  end
76
36
 
77
- def update(href, options = {})
78
- collection = drops_at href
79
- drop = collection.items.first
80
- path = options.fetch :path, nil
81
- attributes = drop.data.merge fetch_drop_attributes(options)
82
- data = collection.template.fill attributes
83
-
84
- put(drop.href, data) do |collection|
85
- if not path
86
- return collection
87
- else
88
- return upload_file(path, collection)
89
- end
37
+ def token_for_account email, password
38
+ template = root.template
39
+ .fill('email', email)
40
+ .fill('password', password)
41
+ post template.href, template.data do |representation|
42
+ return unless representation.authorized?
43
+ return representation.item.data.fetch('token')
90
44
  end
91
45
  end
92
46
 
93
- def bookmark(url, options = {})
94
- attributes = fetch_drop_attributes options.merge(url: url)
95
- collection = drops_at :root
96
- data = collection.template.fill(attributes)
97
-
98
- post(collection.href, data) do |response|
99
- return DropCollection.new response, self
47
+ def bookmark url
48
+ template = drops_template.template.
49
+ fill('bookmark_url', url)
50
+ post template.href, template.data do |representation|
51
+ return representation.item
100
52
  end
101
53
  end
102
54
 
103
- def upload(path, options = {})
104
- attributes = fetch_drop_attributes options.merge(path: path)
105
- collection = drops_at :root
106
- data = collection.template.fill(attributes)
107
-
108
- post(collection.href, data) do |collection|
109
- return DropCollection.new upload_file(path, collection), self
55
+ def upload path
56
+ template = drops_template.template.
57
+ fill('file_size', FileTest.size(path))
58
+ post template.href, template.data do |representation|
59
+ return upload_file(path, representation.template)
110
60
  end
111
61
  end
112
62
 
113
- def trash_drop(href)
114
- update href, trash: true
115
- end
116
-
117
- def recover_drop(href)
118
- update href, trash: false
119
- end
120
-
121
- def delete_drop(href)
122
- delete(href) do |response|
123
- return response
63
+ def drops_template
64
+ root.link('drops-template').get do |representation|
65
+ return representation
124
66
  end
125
67
  end
126
68
 
127
69
  private
128
70
 
129
- def drops_at(href, params = {})
130
- params = params.each_with_object({}) {|(key, value), params|
131
- params[key.to_s] = value
132
- }
133
-
134
- if href == :root
135
- get('/') do |response|
136
- return response if response.__response__.status == 401
137
- href = response.link('drops').href
138
- end
139
- end
140
-
141
- get(href) do |response|
142
- return response if response.__response__.status == 401
143
- if not params.empty?
144
- drops_query = response.query('drops-list')
145
- href = Addressable::URI.parse drops_query.href
146
- href.query_values = drops_query.fill params
147
- else
148
- return response
149
- end
150
- end
151
-
152
- get(href) do |response|
153
- return response if response.__response__.status == 401
154
- return response
155
- end
156
- end
157
-
158
- def fetch_drop_attributes(options)
159
- path = options.delete :path
160
- options[:file_size] = FileTest.size(path) if path
161
- { url: 'bookmark_url',
162
- file_size: 'file_size',
163
- name: 'name',
164
- private: 'private',
165
- trash: 'trash'
166
- }.each_with_object({}) {|(key, name), attributes|
167
- attributes[name] = options.fetch(key) if options.has_key?(key)
168
- }
169
- end
170
-
171
- def upload_file(path, collection)
172
- uri = Addressable::URI.parse collection.href
173
- file = File.open path
174
- file_io = Faraday::UploadIO.new file, 'image/png'
175
- fields = collection.template.fill('file' => file_io)
71
+ def upload_file(path, template)
72
+ file = File.open path
73
+ file_io = Faraday::UploadIO.new file, 'image/png' # TODO: Use correct mime type
74
+ template = template.fill('file', file_io)
75
+ uri = Addressable::URI.parse template.href
176
76
 
177
77
  conn = Faraday.new(url: uri.site) {|builder|
178
- if collection.template.enctype == Faraday::Request::Multipart.mime_type
179
- builder.request :multipart
180
- end
181
-
78
+ builder.request :multipart
182
79
  builder.response :logger, logger
183
80
  builder.adapter :typhoeus
184
81
  }
185
82
 
186
- conn.post(uri.request_uri, fields).on_complete do |env|
83
+ conn.post(uri.request_uri, template.data).on_complete do |env|
187
84
  location = Addressable::URI.parse env[:response_headers]['Location']
188
- get(location) do |upload_response|
189
- return upload_response
85
+ get location do |upload_response|
86
+ return upload_response.item
190
87
  end
191
88
  end
192
89
  end
data/lib/cloudapp.rb CHANGED
@@ -1,5 +1,3 @@
1
- require 'cloudapp/service'
2
-
3
1
  module CloudApp
4
- VERSION = '2.0.0.beta.4'
2
+ VERSION = '2.0.0.beta.5'
5
3
  end
data/man/cloudapp.1 ADDED
@@ -0,0 +1,100 @@
1
+ .\" generated with Ronn/v0.7.3
2
+ .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
+ .
4
+ .TH "CLOUDAPP" "1" "December 2012" "" ""
5
+ .
6
+ .SH "NAME"
7
+ \fBcloudapp\fR \- all the pleasures of cloudapp in a cli
8
+ .
9
+ .SH "SYNOPSIS"
10
+ \fBcloudapp bookmark\fR [\fB\-\-direct\fR] \fIurl\fR
11
+ .
12
+ .br
13
+ \fBcloudapp upload\fR [\fB\-\-direct\fR] \fIfile\fR
14
+ .
15
+ .SH "DESCRIPTION"
16
+ Upload a file or share a bookmark with CloudApp\. The drop\'s share link will be printed to standard output\. Account credentials are stored in \fB~/\.netrc\fR\.
17
+ .
18
+ .SH "OPTIONS"
19
+ .
20
+ .TP
21
+ \fB\-d\fR, \fB\-\-direct\fR
22
+ Print the drop\'s direct link after creation\. The direct link is suitable for use in places that expect a link to a file content like an HTML IMG tag\.
23
+ .
24
+ .SH "EXIT STATUS"
25
+ cloudapp may return one of several error codes if it encouters problems\.
26
+ .
27
+ .IP "\(bu" 4
28
+ \fB0\fR Success
29
+ .
30
+ .IP "\(bu" 4
31
+ \fB1\fR File exceeds the limits of the account\'s plan
32
+ .
33
+ .IP "\(bu" 4
34
+ \fB9\fR Something horrible has happened
35
+ .
36
+ .IP "" 0
37
+ .
38
+ .SH "FILES"
39
+ .
40
+ .TP
41
+ \fB$HOME/\.netrc\fR
42
+ Store account authentication token
43
+ .
44
+ .SH "EXAMPLE"
45
+ Upload a file:
46
+ .
47
+ .IP "" 4
48
+ .
49
+ .nf
50
+
51
+ $ cloudapp upload screenshot\.png
52
+ http://cl\.ly/abc123
53
+ .
54
+ .fi
55
+ .
56
+ .IP "" 0
57
+ .
58
+ .P
59
+ Copy the drop\'s share link to the clipboard on OS X:
60
+ .
61
+ .IP "" 4
62
+ .
63
+ .nf
64
+
65
+ $ cloudapp upload screenshot\.png | pbcopy
66
+ .
67
+ .fi
68
+ .
69
+ .IP "" 0
70
+ .
71
+ .P
72
+ Bookmark a URL:
73
+ .
74
+ .IP "" 4
75
+ .
76
+ .nf
77
+
78
+ $ cloudapp bookmark http://getcloudapp\.com
79
+ http://cl\.ly/abc123
80
+ .
81
+ .fi
82
+ .
83
+ .IP "" 0
84
+ .
85
+ .P
86
+ Print the drop\'s direct link:
87
+ .
88
+ .IP "" 4
89
+ .
90
+ .nf
91
+
92
+ $ cloudapp upload \-\-direct screenshot\.png
93
+ http://cl\.ly/abc123/screenshot\.png
94
+ .
95
+ .fi
96
+ .
97
+ .IP "" 0
98
+ .
99
+ .SH "SEE ALSO"
100
+ \fBftp\fR(1)
@@ -0,0 +1,157 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv='content-type' value='text/html;charset=utf8'>
5
+ <meta name='generator' value='Ronn/v0.7.3 (http://github.com/rtomayko/ronn/tree/0.7.3)'>
6
+ <title>cloudapp(1) - all the pleasures of cloudapp in a cli</title>
7
+ <style type='text/css' media='all'>
8
+ /* style: man */
9
+ body#manpage {margin:0}
10
+ .mp {max-width:100ex;padding:0 9ex 1ex 4ex}
11
+ .mp p,.mp pre,.mp ul,.mp ol,.mp dl {margin:0 0 20px 0}
12
+ .mp h2 {margin:10px 0 0 0}
13
+ .mp > p,.mp > pre,.mp > ul,.mp > ol,.mp > dl {margin-left:8ex}
14
+ .mp h3 {margin:0 0 0 4ex}
15
+ .mp dt {margin:0;clear:left}
16
+ .mp dt.flush {float:left;width:8ex}
17
+ .mp dd {margin:0 0 0 9ex}
18
+ .mp h1,.mp h2,.mp h3,.mp h4 {clear:left}
19
+ .mp pre {margin-bottom:20px}
20
+ .mp pre+h2,.mp pre+h3 {margin-top:22px}
21
+ .mp h2+pre,.mp h3+pre {margin-top:5px}
22
+ .mp img {display:block;margin:auto}
23
+ .mp h1.man-title {display:none}
24
+ .mp,.mp code,.mp pre,.mp tt,.mp kbd,.mp samp,.mp h3,.mp h4 {font-family:monospace;font-size:14px;line-height:1.42857142857143}
25
+ .mp h2 {font-size:16px;line-height:1.25}
26
+ .mp h1 {font-size:20px;line-height:2}
27
+ .mp {text-align:justify;background:#fff}
28
+ .mp,.mp code,.mp pre,.mp pre code,.mp tt,.mp kbd,.mp samp {color:#131211}
29
+ .mp h1,.mp h2,.mp h3,.mp h4 {color:#030201}
30
+ .mp u {text-decoration:underline}
31
+ .mp code,.mp strong,.mp b {font-weight:bold;color:#131211}
32
+ .mp em,.mp var {font-style:italic;color:#232221;text-decoration:none}
33
+ .mp a,.mp a:link,.mp a:hover,.mp a code,.mp a pre,.mp a tt,.mp a kbd,.mp a samp {color:#0000ff}
34
+ .mp b.man-ref {font-weight:normal;color:#434241}
35
+ .mp pre {padding:0 4ex}
36
+ .mp pre code {font-weight:normal;color:#434241}
37
+ .mp h2+pre,h3+pre {padding-left:0}
38
+ ol.man-decor,ol.man-decor li {margin:3px 0 10px 0;padding:0;float:left;width:33%;list-style-type:none;text-transform:uppercase;color:#999;letter-spacing:1px}
39
+ ol.man-decor {width:100%}
40
+ ol.man-decor li.tl {text-align:left}
41
+ ol.man-decor li.tc {text-align:center;letter-spacing:4px}
42
+ ol.man-decor li.tr {text-align:right;float:right}
43
+ </style>
44
+ <style type='text/css' media='all'>
45
+ /* style: toc */
46
+ .man-navigation {display:block !important;position:fixed;top:0;left:113ex;height:100%;width:100%;padding:48px 0 0 0;border-left:1px solid #dbdbdb;background:#eee}
47
+ .man-navigation a,.man-navigation a:hover,.man-navigation a:link,.man-navigation a:visited {display:block;margin:0;padding:5px 2px 5px 30px;color:#999;text-decoration:none}
48
+ .man-navigation a:hover {color:#111;text-decoration:underline}
49
+ </style>
50
+ </head>
51
+ <!--
52
+ The following styles are deprecated and will be removed at some point:
53
+ div#man, div#man ol.man, div#man ol.head, div#man ol.man.
54
+
55
+ The .man-page, .man-decor, .man-head, .man-foot, .man-title, and
56
+ .man-navigation should be used instead.
57
+ -->
58
+ <body id='manpage'>
59
+ <div class='mp' id='man'>
60
+
61
+ <div class='man-navigation' style='display:none'>
62
+ <a href="#NAME">NAME</a>
63
+ <a href="#SYNOPSIS">SYNOPSIS</a>
64
+ <a href="#DESCRIPTION">DESCRIPTION</a>
65
+ <a href="#OPTIONS">OPTIONS</a>
66
+ <a href="#EXIT-STATUS">EXIT STATUS</a>
67
+ <a href="#FILES">FILES</a>
68
+ <a href="#EXAMPLE">EXAMPLE</a>
69
+ <a href="#SEE-ALSO">SEE ALSO</a>
70
+ </div>
71
+
72
+ <ol class='man-decor man-head man head'>
73
+ <li class='tl'>cloudapp(1)</li>
74
+ <li class='tc'></li>
75
+ <li class='tr'>cloudapp(1)</li>
76
+ </ol>
77
+
78
+ <h2 id="NAME">NAME</h2>
79
+ <p class="man-name">
80
+ <code>cloudapp</code> - <span class="man-whatis">all the pleasures of cloudapp in a cli</span>
81
+ </p>
82
+
83
+ <h2 id="SYNOPSIS">SYNOPSIS</h2>
84
+
85
+ <p><code>cloudapp bookmark</code> [<code>--direct</code>] <var>url</var><br />
86
+ <code>cloudapp upload</code> [<code>--direct</code>] <var>file</var></p>
87
+
88
+ <h2 id="DESCRIPTION">DESCRIPTION</h2>
89
+
90
+ <p>Upload a file or share a bookmark with CloudApp. The drop's share link will be
91
+ printed to standard output. Account credentials are stored in <code>~/.netrc</code>.</p>
92
+
93
+ <h2 id="OPTIONS">OPTIONS</h2>
94
+
95
+ <dl>
96
+ <dt><code>-d</code>, <code>--direct</code></dt><dd>Print the drop's direct link after creation. The direct link is suitable for
97
+ use in places that expect a link to a file content like an HTML IMG tag.</dd>
98
+ </dl>
99
+
100
+
101
+ <h2 id="EXIT-STATUS">EXIT STATUS</h2>
102
+
103
+ <p>cloudapp may return one of several error codes if it encouters problems.</p>
104
+
105
+ <ul>
106
+ <li><code>0</code> Success</li>
107
+ <li><code>1</code> File exceeds the limits of the account's plan</li>
108
+ <li><code>9</code> Something horrible has happened</li>
109
+ </ul>
110
+
111
+
112
+ <h2 id="FILES">FILES</h2>
113
+
114
+ <dl>
115
+ <dt><code>$HOME/.netrc</code></dt><dd>Store account authentication token</dd>
116
+ </dl>
117
+
118
+
119
+ <h2 id="EXAMPLE">EXAMPLE</h2>
120
+
121
+ <p>Upload a file:</p>
122
+
123
+ <pre><code>$ cloudapp upload screenshot.png
124
+ http://cl.ly/abc123
125
+ </code></pre>
126
+
127
+ <p>Copy the drop's share link to the clipboard on OS X:</p>
128
+
129
+ <pre><code>$ cloudapp upload screenshot.png | pbcopy
130
+ </code></pre>
131
+
132
+ <p>Bookmark a URL:</p>
133
+
134
+ <pre><code>$ cloudapp bookmark http://getcloudapp.com
135
+ http://cl.ly/abc123
136
+ </code></pre>
137
+
138
+ <p>Print the drop's direct link:</p>
139
+
140
+ <pre><code>$ cloudapp upload --direct screenshot.png
141
+ http://cl.ly/abc123/screenshot.png
142
+ </code></pre>
143
+
144
+ <h2 id="SEE-ALSO">SEE ALSO</h2>
145
+
146
+ <p><code>ftp</code>(1)</p>
147
+
148
+
149
+ <ol class='man-decor man-foot man foot'>
150
+ <li class='tl'></li>
151
+ <li class='tc'>December 2012</li>
152
+ <li class='tr'>cloudapp(1)</li>
153
+ </ol>
154
+
155
+ </div>
156
+ </body>
157
+ </html>
@@ -0,0 +1,56 @@
1
+ cloudapp(1) -- all the pleasures of cloudapp in a cli
2
+ =====================================================
3
+
4
+ ## SYNOPSIS
5
+
6
+ `cloudapp bookmark` [`--direct`] <url><br>
7
+ `cloudapp upload` [`--direct`] <file>
8
+
9
+ ## DESCRIPTION
10
+
11
+ Upload a file or share a bookmark with CloudApp. The drop's share link will be
12
+ printed to standard output. Account credentials are stored in `~/.netrc`.
13
+
14
+ ## OPTIONS
15
+
16
+ - `-d`, `--direct`:
17
+ Print the drop's direct link after creation. The direct link is suitable for
18
+ use in places that expect a link to a file content like an HTML IMG tag.
19
+
20
+ ## EXIT STATUS
21
+
22
+ cloudapp may return one of several error codes if it encouters problems.
23
+
24
+ - `0` Success
25
+ - `1` File exceeds the limits of the account's plan
26
+ - `9` Something horrible has happened
27
+
28
+ ## FILES
29
+
30
+ - `$HOME/.netrc`:
31
+ Store account authentication token
32
+
33
+ ## EXAMPLE
34
+
35
+ Upload a file:
36
+
37
+ $ cloudapp upload screenshot.png
38
+ http://cl.ly/abc123
39
+
40
+ Copy the drop's share link to the clipboard on OS X:
41
+
42
+ $ cloudapp upload screenshot.png | pbcopy
43
+
44
+ Bookmark a URL:
45
+
46
+ $ cloudapp bookmark http://getcloudapp.com
47
+ http://cl.ly/abc123
48
+
49
+ Print the drop's direct link:
50
+
51
+ $ cloudapp upload --direct screenshot.png
52
+ http://cl.ly/abc123/screenshot.png
53
+
54
+ ## SEE ALSO
55
+
56
+ `ftp`(1)