putio-rb 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f712fea4767df51ec90b69b5592d0ed3a5e38689
4
+ data.tar.gz: abd9eb37ff2832cb85aa81239f83b7c6722a5d36
5
+ SHA512:
6
+ metadata.gz: ab42d068ab464bce698480b2f13164087fabf270a8d155cccb114f0f8367d96acd7606fc3007f9fdcf72b785d4c37b520cb30dca0121450eb4a3d3a8e9951da3
7
+ data.tar.gz: 18321b87e58939c827af1acfe13fb4a9e2b922088273b6b4c8a74b18783f11902ad5269942f208565bacd121822ed0ab03f32ec75fe7970a86a526b7d2d26d35
@@ -0,0 +1,5 @@
1
+ .DS_Store
2
+ *.gem
3
+ .ruby-version
4
+ doc/
5
+ .yardoc/
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.1.2
5
+
6
+ before_install:
7
+ - 'echo ''gem: --no-ri --no-rdoc'' > ~/.gemrc'
8
+
9
+ script: bundle exec rake
data/Gemfile ADDED
@@ -0,0 +1,18 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rake'
4
+
5
+ group :development do
6
+ gem 'yard'
7
+ end
8
+
9
+ group :test do
10
+ gem 'rspec'
11
+ gem 'guard-rspec'
12
+ gem 'webmock'
13
+ gem 'pry'
14
+ gem 'pry-nav'
15
+ gem 'terminal-notifier-guard'
16
+ end
17
+
18
+ gemspec
@@ -0,0 +1,78 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ putio-rb (0.0.2)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ addressable (2.3.6)
10
+ celluloid (0.15.2)
11
+ timers (~> 1.1.0)
12
+ coderay (1.1.0)
13
+ crack (0.4.2)
14
+ safe_yaml (~> 1.0.0)
15
+ diff-lcs (1.2.5)
16
+ ffi (1.9.3)
17
+ formatador (0.2.5)
18
+ guard (2.6.1)
19
+ formatador (>= 0.2.4)
20
+ listen (~> 2.7)
21
+ lumberjack (~> 1.0)
22
+ pry (>= 0.9.12)
23
+ thor (>= 0.18.1)
24
+ guard-rspec (4.3.1)
25
+ guard (~> 2.1)
26
+ rspec (>= 2.14, < 4.0)
27
+ listen (2.7.9)
28
+ celluloid (>= 0.15.2)
29
+ rb-fsevent (>= 0.9.3)
30
+ rb-inotify (>= 0.9)
31
+ lumberjack (1.0.9)
32
+ method_source (0.8.2)
33
+ pry (0.10.0)
34
+ coderay (~> 1.1.0)
35
+ method_source (~> 0.8.1)
36
+ slop (~> 3.4)
37
+ pry-nav (0.2.4)
38
+ pry (>= 0.9.10, < 0.11.0)
39
+ rake (10.1.0)
40
+ rb-fsevent (0.9.4)
41
+ rb-inotify (0.9.5)
42
+ ffi (>= 0.5.0)
43
+ rspec (3.0.0)
44
+ rspec-core (~> 3.0.0)
45
+ rspec-expectations (~> 3.0.0)
46
+ rspec-mocks (~> 3.0.0)
47
+ rspec-core (3.0.3)
48
+ rspec-support (~> 3.0.0)
49
+ rspec-expectations (3.0.3)
50
+ diff-lcs (>= 1.2.0, < 2.0)
51
+ rspec-support (~> 3.0.0)
52
+ rspec-mocks (3.0.3)
53
+ rspec-support (~> 3.0.0)
54
+ rspec-support (3.0.3)
55
+ safe_yaml (1.0.3)
56
+ slop (3.6.0)
57
+ terminal-notifier-guard (1.5.3)
58
+ thor (0.19.1)
59
+ timers (1.1.0)
60
+ webmock (1.18.0)
61
+ addressable (>= 2.3.6)
62
+ crack (>= 0.3.2)
63
+ yard (0.8.7.4)
64
+
65
+ PLATFORMS
66
+ ruby
67
+
68
+ DEPENDENCIES
69
+ bundler
70
+ guard-rspec
71
+ pry
72
+ pry-nav
73
+ putio-rb!
74
+ rake
75
+ rspec
76
+ terminal-notifier-guard
77
+ webmock
78
+ yard
@@ -0,0 +1,6 @@
1
+ guard :rspec, cmd: 'bundle exec rspec' do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ watch(%r{^spec/support/shared_examples/(.+)\.rb$}) { "spec" }
6
+ end
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013-2014 Thibault Gautriaud
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,97 @@
1
+ # putio-rb [![Build Status](https://travis-ci.org/hubb/putio.rb.svg?branch=master)](https://travis-ci.org/hubb/putio.rb)
2
+
3
+ A wrapper around [put.io](https://put.io) api v2 which allows you to access all
4
+ your files and transfers.
5
+
6
+ ## Install
7
+
8
+ gem install putio-rb
9
+
10
+ ## Usage
11
+
12
+ First, you'll need to generate an access token, please see [the documentation](http://put.io/v2/docs/gettingstarted.html#authentication-and-access).
13
+
14
+ ### Configuration
15
+
16
+ ```
17
+ require 'putio-rb'
18
+
19
+ Putio.configure do |config|
20
+ config.access_token = 'SECRET TOKEN' # mandatory
21
+ config.api_endpoint = 'https://foo.bar'
22
+ config.api_version = 'v1'
23
+ config.user_agent = 'kthxbye'
24
+ end
25
+ ```
26
+
27
+ ### Files
28
+
29
+ ```
30
+ # list all files
31
+ client.list_files
32
+ # also aliased as files
33
+ client.files
34
+ # list files in directory 123
35
+ client.files(options: { parent_id: 123 })
36
+ # search a file
37
+ client.search query: 'foo'
38
+ # complex search
39
+ client.search(query: 'jazz', options: { from: 'me,jack', ext: 'mp4', time: 'today' })
40
+ # find a file
41
+ client.file id: 123
42
+ # delete files 123 and 345
43
+ client.delete_files(123, 345)
44
+ ```
45
+
46
+ ### Transfers
47
+
48
+ ```
49
+ # list all transfers
50
+ client.list_transfers
51
+ # also aliased as transfers
52
+ client.transfers
53
+ ```
54
+
55
+ ## Todo
56
+
57
+ ### Files
58
+
59
+ - [x] list files
60
+ - [x] search files
61
+ - [ ] upload file
62
+ - [ ] create folder
63
+ - [x] get file
64
+ - [x] delete file
65
+ - [ ] rename file
66
+ - [ ] move file
67
+ - [ ] convert file to mp4
68
+ - [ ] get mp4 status
69
+ - [ ] download
70
+ - [ ] zip & download
71
+ - [ ] subtitles
72
+ - [ ] download subtitles
73
+
74
+ ### Transfers
75
+
76
+ - [x] list transfers
77
+ - [ ] add transfer
78
+ - [ ] get transfer
79
+ - [ ] retry transfer
80
+ - [ ] cancel transfer
81
+ - [ ] clean transfers
82
+
83
+ ### Friends
84
+
85
+ - [ ] list friends
86
+ - [ ] friend requests
87
+ - [ ] send request
88
+ - [ ] deny request
89
+
90
+ ### Account
91
+
92
+ - [ ] info
93
+ - [ ] settings
94
+
95
+ ## License
96
+
97
+ See [LICENSE](https://github.com/hubb/putio.rb/blob/master/LICENSE.md)
@@ -0,0 +1,23 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :test => :spec
8
+ task :default => :spec
9
+
10
+ namespace :doc do
11
+ begin
12
+ require 'yard'
13
+ YARD::Rake::YardocTask.new do |task|
14
+ task.files = ['README.md', 'LICENSE.md', 'lib/**/*.rb']
15
+ task.options = [
16
+ '--output-dir', 'doc/yard',
17
+ '--markup', 'markdown',
18
+ ]
19
+ end
20
+ rescue LoadError
21
+ puts "Please install yard for documentation support: gem install yard"
22
+ end
23
+ end
@@ -0,0 +1,22 @@
1
+ lib = File.expand_path('lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ require 'putio/client'
5
+ require 'forwardable'
6
+
7
+ module Putio
8
+ class << self
9
+ include Putio::Configurable
10
+ extend Forwardable
11
+
12
+ def_delegators :client,
13
+ :list_files, :files, :search, :file, :delete_file,
14
+ :list_transfers, :transfers
15
+
16
+ def client
17
+ @client ||= Client.new(options)
18
+ end
19
+ end
20
+ end
21
+
22
+ Putio.setup
@@ -0,0 +1,81 @@
1
+ require 'putio/connection'
2
+ require 'putio/defaults'
3
+ require 'putio/configurable'
4
+ require 'putio/client/files'
5
+ require 'putio/client/transfers'
6
+
7
+ module Putio
8
+ class Client
9
+ include Putio::Configurable
10
+ include Putio::Client::Files
11
+ include Putio::Client::Transfers
12
+
13
+ attr_writer :connection
14
+
15
+ def initialize(options = {})
16
+ Putio::Configurable.keys.each do |key|
17
+ public_send(:"#{key}=", options.fetch(key) { Putio.public_send(:"#{key}") })
18
+ end
19
+ end
20
+
21
+ # Text representation of the client, access token being masked
22
+ #
23
+ # @return [String]
24
+ def inspect
25
+ inspected = super
26
+ # mask access_token
27
+ inspected = inspected.gsub! access_token, "*******" if access_token
28
+ inspected
29
+ end
30
+
31
+ # Make a HTTP GET request
32
+ #
33
+ # @param path [String] The path, relative to {#api_endpoint}
34
+ # @param options [Hash] Query and header params for request
35
+ # @return [Putio::Resource]
36
+ def get(path, options = {})
37
+ request :get, path, options
38
+ end
39
+
40
+ # Make a HTTP POST request
41
+ #
42
+ # @param path [String] The path, relative to {#api_endpoint}
43
+ # @param options [Hash] Body and header params for request
44
+ # @return [Putio::Resource]
45
+ def post(path, options = {})
46
+ request :post, path, options
47
+ end
48
+
49
+ # Make a HTTP PUT request
50
+ #
51
+ # @param path [String] The path, relative to {#api_endpoint}
52
+ # @param options [Hash] Body and header params for request
53
+ # @return [Putio::Resource]
54
+ def put(path, options = {})
55
+ request :put, path, options
56
+ end
57
+
58
+ # Make a HTTP DELETE request
59
+ #
60
+ # @param path [String] The path, relative to {#api_endpoint}
61
+ # @param options [Hash] Query and header params for request
62
+ # @return [Putio::Resource]
63
+ def delete(path, options = {})
64
+ request :delete, path, options
65
+ end
66
+
67
+ private
68
+ def request(method, path, params)
69
+ params = params.merge(oauth_token: access_token)
70
+ path = File.join('/', api_version, path)
71
+
72
+ connection.request_json(method, path, params)
73
+ end
74
+
75
+ def connection
76
+ @connection ||= Connection.new(endpoint: api_endpoint,
77
+ headers: default_headers)
78
+ end
79
+
80
+ end
81
+ end
@@ -0,0 +1,107 @@
1
+ require 'putio/resource/file'
2
+
3
+ module Putio
4
+
5
+ class Client
6
+
7
+ module Files
8
+ # Lists files in a folder
9
+ #
10
+ # @param options [Hash]
11
+ # @option options [Integer] parent_id: ID of the folder you’d like to list. This defaults to the root directory (which has ID number 0).
12
+ # @alias files
13
+ #
14
+ # @return [Array<Putio::Resource::File>]
15
+ def list_files(options:{})
16
+ defaults = { parent_id: 0 }
17
+ options = defaults.merge!(options)
18
+
19
+ resp = get '/files/list', options
20
+ resp.body["files"].inject([]) do |memo, data|
21
+ memo.push file_factory.call(data)
22
+ end
23
+ end
24
+ alias :files :list_files
25
+
26
+ # Search a file
27
+ #
28
+ # @param query [String] The keyword to search
29
+ # @param options [Hash] Search Syntax params
30
+ # @option options [Integer] page: Defaults to 1. If -1 given, returns all results at a time.
31
+ # @option options [String] from: me, shares, jack or all
32
+ # @option options [String] type: video, audio, image, iphone or all
33
+ # @option options [String] ext: mp3, avi, jpg, mp4 or all
34
+ # @option options [String] time: today, yesterday, thisweek or all
35
+ # @example
36
+ # result = client.search(query: "foo")
37
+ # # => returns first page of results for "foo"
38
+ #
39
+ # result = client.search(query: "foo", page: 2)
40
+ # # => returns page 2 of results for "foo"
41
+ #
42
+ # result = client.search(query: "foo", page:-1)
43
+ # # => returns all results for "foo"
44
+ #
45
+ # result = client.search(query: 'jazz', options: { from: 'me,jack', ext: 'mp4', time: 'today' })
46
+ # # => Searches yours and jack’s files with the word jazz in its title which has the extension mp3 and created today.
47
+ #
48
+ # result = client.search(query: 'jazz album', options: { from: 'shares', time: 'thisweek' })
49
+ # # => Searches items shared with you with jazz album which are created thisweek
50
+ #
51
+ # result = client.search(query: 'jazz', options: { type: 'iphone' })
52
+ # # => Searches your files and items shared with the word jazz in its title which are converted to mp4
53
+ #
54
+ # @return [Array<Putio::Resource::File>]
55
+ def search(query:, options: {})
56
+ valid_search_options = %i{ page from type ext time }
57
+ options.select! { |o| valid_search_options.include?(o) }
58
+
59
+ page = options.delete(:page)
60
+ path = if page
61
+ "/files/search/#{query}/page/#{page}"
62
+ else
63
+ "/files/search/#{query}"
64
+ end
65
+
66
+ resp = get path, options
67
+
68
+ resp.body["files"].inject([]) do |memo, data|
69
+ memo.push file_factory.call(data)
70
+ end
71
+ end
72
+
73
+ # Returns a file’s properties.
74
+ #
75
+ # @param id [Integer]
76
+ # @param options
77
+ # @option options [Integer] parent_id: ID of the folder you’d like to list. This defaults to the root directory (which has ID number 0).
78
+ # @return [Putio::Resource::File]
79
+ def file(id:, options:{})
80
+ defaults = { parent_id: 0 }
81
+ options = defaults.merge!(options)
82
+
83
+ resp = get "/files/#{id}", options
84
+ file_factory.call(resp.body["file"])
85
+ end
86
+
87
+ # Deletes given files
88
+ #
89
+ # @param file_ids [Array<Integer>] File ids separated by commas. Ex: 1,2,3,4
90
+ # Returns [true]
91
+ def delete_files(*file_ids)
92
+ resp = post '/files/delete', { file_ids: file_ids.join(',') }
93
+
94
+ if resp.body["status"] == "OK"
95
+ true
96
+ else
97
+ false
98
+ end
99
+ end
100
+
101
+ private
102
+ def file_factory
103
+ @file_factory ||= Putio::Resource::File.public_method(:new)
104
+ end
105
+ end
106
+ end
107
+ end