Skip to content
This repository was archived by the owner on Dec 11, 2020. It is now read-only.

Commit 8138841

Browse files
committed
Rename communication module
Start documenting the behavior better
1 parent 9ee34dc commit 8138841

File tree

12 files changed

+49
-42
lines changed

12 files changed

+49
-42
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,5 @@ matrix:
1212
allow_failures:
1313
- rvm: jruby-9.0
1414
script:
15-
- 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then bundle exec rspec --exclude-pattern "spec/integration_spec.rb"; fi'
16-
- 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then bundle exec rspec; fi'
15+
- RUBYOPT="--enable-frozen-string-literal" bundle exec rspec
1716
- bundle exec rubocop -c .rubocop.yml --force-exclusion

README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ For your API key and additional info please visit our [developer portal](https:/
2424
Add this line to your application's Gemfile:
2525

2626
```ruby
27-
gem 'wetransfer', version: '0.9.0.beta2'
27+
gem 'wetransfer', version: '0.9.0.beta3'
2828
```
2929

3030
And then execute:
@@ -57,7 +57,7 @@ Open the file in your text editor and add this line:
5757

5858
WT_API_KEY=<your api key>
5959

60-
Make sure to replace `<your api key>` by your actual api key. Don't include the pointy brackets!
60+
Make sure to replace `<your api key>` with your actual api key. Don't include the pointy brackets!
6161

6262
Great! Now you can go to your project file and use the client.
6363

@@ -66,8 +66,8 @@ Great! Now you can go to your project file and use the client.
6666
A transfer is a collection of files that can be created once, and downloaded until it expires. Once a transfer is ready for sharing, it is closed for modifications.
6767

6868
```ruby
69-
# In your project file:
70-
require 'we_transfer_client'
69+
# In your proje ct file:
70+
require 'we_transfer'
7171

7272
client = WeTransfer::Client.new(api_key: ENV.fetch('WT_API_KEY'))
7373
```
@@ -97,7 +97,7 @@ Boards need a WeTransfer Client to be present, just like transfers.
9797

9898
```ruby
9999
# In your project file:
100-
require 'we_transfer_client'
100+
require 'we_transfer'
101101

102102
client = WeTransfer::Client.new(api_key: ENV.fetch('WT_API_KEY'))
103103
```
@@ -106,7 +106,6 @@ After you create your client, you can
106106

107107
### Create a board and upload items
108108

109-
110109
```ruby
111110
board = client.create_board(name: 'Meow', description: 'On Cats') do |items|
112111
items.add_file(name: 'big file.jpg', io: File.open('/path/to/huge_file.jpg', 'rb')items.add_file_at(path: '/path/to/another/file.txt')
@@ -150,12 +149,12 @@ Hooray!
150149

151150
## Contributing
152151

153-
Bug reports and pull requests are welcome on GitHub at https://github.com/wetransfer/wetransfer_ruby_sdk. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct. More extensive contribution guidelines can be found [here](https://github.com/WeTransfer/wetransfer_ruby_sdk/blob/master/.github/CONTRIBUTING.md).
152+
Bug reports and pull requests are welcome on GitHub at <https://github.com/wetransfer/wetransfer_ruby_sdk.> This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct. More extensive contribution guidelines can be found [here](https://github.com/WeTransfer/wetransfer_ruby_sdk/blob/master/.github/CONTRIBUTING.md).
154153

155154
## License
156155

157156
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT) - the in-repo version of the license is [here](https://github.com/WeTransfer/wetransfer_ruby_sdk/blob/master/LICENSE.txt).
158157

159158
## Code of Conduct
160159

161-
Everyone interacting in the WeTransfer Ruby SDK project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/WeTransfer/wetransfer_ruby_sdk/blob/master/.github/CODE_OF_CONDUCT.md).
160+
Everyone interacting in the WeTransfer Ruby SDK project’s code bases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/WeTransfer/wetransfer_ruby_sdk/blob/master/.github/CODE_OF_CONDUCT.md).

bin/console

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env ruby
22

33
require 'bundler/setup'
4-
require 'we_transfer_client'
4+
require 'we_transfer'
55

66
# You can add fixtures and/or initialization code here to make experimenting
77
# with your gem easier. You can also use a different console, if you like.

examples/create_collection.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require_relative 'we_transfer_client'
1+
require_relative 'we_transfer'
22
require 'dotenv'
33
Dotenv.load
44

examples/create_transfer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require_relative 'we_transfer_client'
1+
require_relative 'we_transfer'
22
require 'dotenv'
33
Dotenv.load
44

lib/we_transfer.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# frozen_string_literal: true
2+
3+
require 'faraday'
4+
require 'logger'
5+
require 'json'
6+
require 'ks'
7+
8+
%w[communication_helper client transfer mini_io we_transfer_file remote_file version].each do |file|
9+
require_relative "we_transfer/#{file}"
10+
end
11+
12+
module WeTransfer; end

lib/we_transfer_client.rb renamed to lib/we_transfer/client.rb

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
11
# frozen_string_literal: true
22

3-
require 'faraday'
4-
require 'logger'
5-
require 'json'
6-
require 'ks'
7-
8-
%w[communication_helper transfer mini_io we_transfer_file remote_file version].each do |file|
9-
require_relative "we_transfer/#{file}"
10-
end
11-
123
module WeTransfer
134
class Client
145
class Error < StandardError; end
15-
include CommunicationHelper
6+
include Communication
167

178
NullLogger = Logger.new(nil)
189

@@ -25,9 +16,9 @@ class Error < StandardError; end
2516
#
2617
# @return [WeTransfer::Client]
2718
def initialize(api_key:, logger: NullLogger)
28-
CommunicationHelper.reset_authentication!
29-
CommunicationHelper.api_key = api_key
30-
CommunicationHelper.logger = logger
19+
Communication.reset_authentication!
20+
Communication.api_key = api_key
21+
Communication.logger = logger
3122
end
3223

3324
def create_transfer(**args, &block)
@@ -38,6 +29,12 @@ def create_transfer(**args, &block)
3829
self
3930
end
4031

32+
def create_transfer_and_upload_files(message:, &block)
33+
transfer = WeTransfer::Transfer.new(args)
34+
transfer.persist(&block)
35+
36+
end
37+
4138
def find_transfer(transfer_id)
4239
@transfer = WeTransfer::Transfer.find(transfer_id)
4340
end

lib/we_transfer/communication_helper.rb renamed to lib/we_transfer/communication.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module WeTransfer
22
class CommunicationError < StandardError; end
33

4-
module CommunicationHelper
4+
module Communication
55
extend Forwardable
66

77
API_URL_BASE = "https://dev.wetransfer.com"

lib/we_transfer/transfer.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class FileMismatchError < StandardError; end
1010

1111
class << self
1212
extend Forwardable
13-
def_delegator CommunicationHelper, :find_transfer, :find
13+
def_delegator Communication, :find_transfer, :find
1414
end
1515

1616
def self.create(message:, &block)
@@ -29,7 +29,7 @@ def persist
2929
yield(self) if block_given?
3030
raise NoFilesAddedError if @unique_file_names.empty?
3131

32-
CommunicationHelper.persist_transfer(self)
32+
Communication.persist_transfer(self)
3333
end
3434

3535
# Add one or more files to a transfer, so a transfer can be created over the
@@ -60,22 +60,22 @@ def upload_file(name:, io: nil)
6060
chunk_contents = StringIO.new(put_io.read(file.multipart.chunk_size))
6161
chunk_contents.rewind
6262

63-
CommunicationHelper.upload_chunk(put_url, chunk_contents)
63+
Communication.upload_chunk(put_url, chunk_contents)
6464
end
6565
end
6666

6767
def upload_url_for_chunk(name:, chunk:)
6868
file_id = find_file_by_name(name).id
69-
CommunicationHelper.upload_url_for_chunk(id, file_id, chunk)
69+
Communication.upload_url_for_chunk(id, file_id, chunk)
7070
end
7171

7272
def complete_file(name:)
7373
file = find_file_by_name(name)
74-
CommunicationHelper.complete_file(id, file.id, file.multipart.chunks)
74+
Communication.complete_file(id, file.id, file.multipart.chunks)
7575
end
7676

7777
def finalize
78-
CommunicationHelper.finalize_transfer(self)
78+
Communication.finalize_transfer(self)
7979
end
8080

8181
def as_request_params

spec/spec_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
add_filter '/spec/'
66
end
77

8-
require 'we_transfer_client'
8+
require 'we_transfer'
99
require 'pry'
1010
require 'rspec'
1111
require 'bundler'

0 commit comments

Comments
 (0)