worochi 0.0.10 → 0.0.12

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: 0ba8b523ca7164198a72a0cb2b02230f6a394012
4
- data.tar.gz: 30d3cba96de58d8c04c6c2498f23e747ee320eef
3
+ metadata.gz: f09519cdd63d8cb13cbf636771bb69b8c0987d7e
4
+ data.tar.gz: 54df12c3131b7cf1c6d270d8503123042ce46e2e
5
5
  SHA512:
6
- metadata.gz: 91d81134ec1ebd38502aadf22f4a90e19d648ae4cb8be0c15712961ad124ea8a57ef2ead0334af2d62a0dfb89270225f5a395880f10ab747238b2d8147806c25
7
- data.tar.gz: 2f1665102e34f54b1f29f17c40da921854ebede6cadd1662fa5f8198f4d79c965f2bb1032b14700f98171f98a15d63c9b618e58c995f14c6bcd259793734f535
6
+ metadata.gz: 1afe2b334b5a04d8f8821b8900d7f7616744f9e677706d8ea6ef9a8ec971aadc085d7210b949fd0fee94292b38de01109b13e53b6ebdfeeea96bd97037145aa8
7
+ data.tar.gz: 628f241bbf0a90da4a4a623a34e61aeb13a57700163ad3c733139d1e489416eb58f5c6c452c6be1a55be0ff99b053199510e3b0fe9e13330cd30aab907c226d5
data/README.md CHANGED
@@ -1,5 +1,169 @@
1
- Worochi
2
- ===============================================================================
1
+ # Worochi
2
+
3
+ ![Coverage Status](https://coveralls.io/repos/Pixelapse/worochi/badge.png?branch=master)
3
4
 
4
5
  Worochi provides a standard way to interface with Ruby API wrappers provided
5
- by various cloud storage services such as Dropbox and Google Drive.
6
+ by various cloud storage services such as Dropbox and Google Drive.
7
+
8
+ ## Installation
9
+
10
+ Worochi can be installed as a gem.
11
+
12
+ gem install worochi
13
+
14
+ ## Documentation
15
+
16
+ [http://rdoc.info/gems/worochi][documentation]
17
+
18
+ [documentation]: http://rdoc.info/gems/worochi
19
+
20
+ ## Basic Usage
21
+
22
+ Pushing files is easy. Just create an agent using the OAuth authorization
23
+ token for the user and then call {Worochi::Agent#push} or {Worochi.push}. File
24
+ origins can be local, HTTP, or Amazon S3 paths.
25
+
26
+ Pushing files to Dropbox:
27
+
28
+ ```ruby
29
+ token = '982n3b989az'
30
+ agent = Worochi.create(:dropbox, token)
31
+ agent.push('test.txt')
32
+ agent.files
33
+ # => ['test.txt']
34
+ ```
35
+
36
+ Pushing multiple files:
37
+
38
+ ```ruby
39
+ agent.push(['a.txt', 'folder1/b.txt', 'http://example.com/c.txt'])
40
+ agent.files
41
+ # => ['a.txt', 'b.txt', 'c.txt']
42
+ ```
43
+
44
+ Pushing files to more than one agent at the same time:
45
+
46
+ ```ruby
47
+ a = Worochi.create(:dropbox, 'hxhrerx')
48
+ b = Worochi.create(:dropbox, 'cdgrhdg')
49
+ Worochi.push('test.txt')
50
+ a.files
51
+ # => ['test.txt']
52
+ b.files
53
+ # => ['test.txt']
54
+ ```
55
+
56
+ Pushing to a specific folder:
57
+
58
+ ```ruby
59
+ agent = Worochi.create(:dropbox, token, { dir: '/folder1' })
60
+ agent.push('a.txt')
61
+
62
+ agent.files
63
+ # => ['a.txt']
64
+
65
+ agent.set_dir('/')
66
+ agent.push('b.txt')
67
+ agent.files
68
+ # => ['b.txt']
69
+
70
+ agent.files_and_folders
71
+ # => ['folder1', 'b.txt']
72
+ agent.files('/folder1')
73
+ # => ['a.txt']
74
+ ```
75
+
76
+ ## Amazon S3 Support
77
+
78
+ Files can be retrieved directly from their Amazon S3 location either using the
79
+ bucket name specified in the configuration or by specifiying a bucket name in
80
+ the path.
81
+
82
+ ```ruby
83
+ Worochi::Config.s3_bucket = 'rawr'
84
+
85
+ agent.push('s3:path/to/file')
86
+ # Retrieves from https://rawr.s3.amazonaws.com/path/to/file?AWSAccessKeyId=...
87
+
88
+ agent.push('s3:pikachu:path/to/file')
89
+ # Retrieves from https://pikachu.s3.amazonaws.com/path/to/file?AWSAccessKeyId=...
90
+ ```
91
+
92
+ This uses Amazon's Ruby SDK to create a presigned URL for the specified file
93
+ and then retrieves the file over HTTPS. `AWS_ACCESS_KEY_ID` and
94
+ `AWS_SECRET_ACCESS_KEY` should be present in your environmental variables for
95
+ this to work.
96
+
97
+ ## OAuth2 Flow
98
+
99
+ Worochi provides helper methods to assist with the OAuth2 authorization flow.
100
+
101
+ Example Rails controller:
102
+
103
+ ```ruby
104
+ class ApiTokensController < ApplicationController
105
+
106
+ # GET /worochi/token/new/:service
107
+ def create
108
+ session[:oauth_flow_state] = state = SecureRandom.hex
109
+ redirect_to oauth.flow_start(state)
110
+ end
111
+
112
+ # GET /worochi/token/callback/:service
113
+ def callback
114
+ raise Error unless session[:oauth_flow_state] == params[:state]
115
+ token = oauth.flow_end(params[:code])
116
+ # token is a hash containing the retrieved access token
117
+ end
118
+
119
+ private
120
+
121
+ def oauth
122
+ service = params[:service].to_sym
123
+ redirect_url = oauth_callback_url(service) # defined in routes.rb
124
+ Worochi::OAuth.new(service, redirect_url)
125
+ end
126
+ end
127
+ ```
128
+
129
+ Service-specific settings for OAuth2 are predefined in the gem, so the
130
+ framework just needs to handle verification of session state (this is usually
131
+ optional) and storing the retrieved access token value.
132
+
133
+ ## Development
134
+
135
+ Each service is implemented as an {Worochi::Agent} object. Below is an
136
+ overview of the files necessary for defining an agent to support a new
137
+ service.
138
+
139
+ The behaviors for each API are defined mainly in two files:
140
+
141
+ /worochi/lib/agent/foo_bar.rb
142
+ /worochi/lib/config/foo_bar.yml
143
+
144
+ Optional helper file:
145
+
146
+ /worochi/lib/helper/foo_bar_helper.rb
147
+
148
+ Test file:
149
+
150
+ /worochi/spec/worochi/agent/foo_bar_spec.rb
151
+
152
+ Use underscore for filenames and corresponding mixed case for class name. The
153
+ class name and service name symbol for the above example would be:
154
+
155
+ class Worochi::Agent::FooBar < Worochi::Agent
156
+ end
157
+
158
+ Worochi.create(:foo_bar, token)
159
+
160
+ RSpec tests use the [VCR](https://github.com/vcr/vcr) gem to record and
161
+ playback real HTTP interactions. Remember to filter out API tokens in the
162
+ recordings.
163
+
164
+ ## Name
165
+
166
+ Worochi is the archaic spelling of
167
+ [Orochi](http://en.wikipedia.org/wiki/Yamata_no_Orochi), a mythical
168
+ eight-headed serpent in Japanese mythology.
169
+
data/lib/worochi/item.rb CHANGED
@@ -133,7 +133,7 @@ class Worochi
133
133
 
134
134
  http = Net::HTTP.new(uri.host, uri.port)
135
135
  http.use_ssl = (uri.scheme == 'https')
136
- request = Net::HTTP::Get.new uri
136
+ request = Net::HTTP::Get.new(uri.request_uri)
137
137
 
138
138
  http.request request do |response|
139
139
  response.read_body do |segment|
data/lib/worochi/oauth.rb CHANGED
@@ -12,7 +12,7 @@ class Worochi
12
12
  attr_reader :client
13
13
 
14
14
  # @param service [Symbol] service name
15
- # @param redirect_url [String] callback URL if required
15
+ # @param redirect_uri [String] callback URL if required
16
16
  def initialize(service, redirect_uri=nil)
17
17
  @options = Worochi::Config.service_opts(service).oauth
18
18
  options.service = service
@@ -38,12 +38,13 @@ class Worochi
38
38
  # Retrieves the token using the temporary authorization code.
39
39
  #
40
40
  # @param code [String] authorization code from the first part
41
- # @return [OAuth2::AccessToken] OAuth2 token
41
+ # @return [Hashie::Mash] OAuth2 token
42
42
  def flow_end(code)
43
43
  client.site = options.token_site || options.site
44
44
  opts = {}
45
45
  opts[:redirect_uri] = options.redirect_uri if options.redirect_uri
46
- client.auth_code.get_token(code, opts)
46
+ token = client.auth_code.get_token(code, opts)
47
+ Hashie::Mash.new(token.to_hash)
47
48
  end
48
49
 
49
50
  alias_method :get_token, :flow_end
@@ -1,4 +1,4 @@
1
1
  class Worochi
2
2
  # Current version of the gem
3
- VERSION = '0.0.10'
3
+ VERSION = '0.0.12'
4
4
  end
data/lib/worochi.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'hashie'
2
2
  require 'aws-sdk'
3
+ require 'net/http'
3
4
  require 'worochi/config'
4
5
  require 'worochi/error'
5
6
  require 'worochi/log'
@@ -1,7 +1,7 @@
1
1
  module TestFiles
2
2
  # Remote file for testing.
3
3
  def remote
4
- @remote ||= OpenStruct.new({
4
+ @remote ||= Hashie::Mash.new({
5
5
  source: 'http://soraven.com/blog/wp-content/uploads/2013/06/sr3.gif',
6
6
  checksum: '3c0d873709da4a08e9d9978f678dbc30a6cc5138182c2fee56db1c0b8b806d67',
7
7
  name: 'sr3.gif',
@@ -23,7 +23,7 @@ module TestFiles
23
23
 
24
24
  # Amazon S3 file for testing.
25
25
  def s3
26
- @s3 ||= OpenStruct.new({
26
+ @s3 ||= Hashie::Mash.new({
27
27
  source: 's3:12061/271934/orig_232903',
28
28
  checksum: 'f0891f199f0966ec1b1d209b91ff3f51273577944dbbe338f1947ae9f33cb79a',
29
29
  name: '__init__.py',
data/worochi.gemspec CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
12
12
 
13
13
  s.authors = ['Raven Jiang']
14
14
  s.email = ['raven@cs.stanford.edu']
15
- s.homepage = 'http://rubygems.org/gems/worochi'
15
+ s.homepage = 'https://github.com/Pixelapse/worochi'
16
16
  s.license = 'MIT'
17
17
 
18
18
  s.files = %w(README.md LICENSE worochi.gemspec)
@@ -34,8 +34,10 @@ Gem::Specification.new do |s|
34
34
  s.add_development_dependency('yard')
35
35
  s.add_development_dependency('simplecov')
36
36
  s.add_development_dependency('coveralls')
37
+ s.add_development_dependency('rake')
38
+ s.add_development_dependency('redcarpet')
37
39
 
38
40
  s.post_install_message = <<-MESSAGE
39
- Worochi says, "RAWRRRRR!!!"
41
+ Worochi says, \033[33;1m"RAWRRRRR!!!"\033[0m
40
42
  MESSAGE
41
43
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: worochi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Raven Jiang
@@ -178,6 +178,34 @@ dependencies:
178
178
  - - '>='
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: rake
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - '>='
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - '>='
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: redcarpet
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - '>='
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - '>='
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
181
209
  description: Provides a standard way to interface with Ruby API wrappers provided
182
210
  by various cloud storage services such as Dropbox and Google Drive.
183
211
  email:
@@ -266,12 +294,11 @@ files:
266
294
  - spec/cassettes/Worochi_Item/_open/opens_a_single_file/with_String_parameter.yml
267
295
  - spec/cassettes/Worochi_Item/_open/opens_a_single_file/with_Hash_parameter.yml
268
296
  - spec/cassettes/Worochi_OAuth/_flow_end/rejects_bad_code.yml
269
- homepage: http://rubygems.org/gems/worochi
297
+ homepage: https://github.com/Pixelapse/worochi
270
298
  licenses:
271
299
  - MIT
272
300
  metadata: {}
273
- post_install_message: |2
274
- Worochi says, "RAWRRRRR!!!"
301
+ post_install_message: " Worochi says, \e[33;1m\"RAWRRRRR!!!\"\e[0m\n"
275
302
  rdoc_options: []
276
303
  require_paths:
277
304
  - lib