bitport 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 15860051d54153d619b2c6070082e65dc291ea82a62d79b0dff9091509ba9286
4
+ data.tar.gz: c859c08dac0977f1baa25d70f95b71dd61cd7ad648fb36e9da7987099ddd6c68
5
+ SHA512:
6
+ metadata.gz: 9c6593f7a5d715ee865eb676bc7d655a768bd746a7af1882857525e02c05a2f8550eb97037f287721a2faff0757e388b7561cfa81f385ce200f8d37969cd85a6
7
+ data.tar.gz: d85ae1f170177172dc055ab0608f1cfcd15f0fca52651a3bb00e128986825639274160e33a1c8bc2d1d22272ba4af8a6ff387a991cddbbd48af1fc48a453a3bf
@@ -0,0 +1,60 @@
1
+ module Bitport
2
+ class Base
3
+ attr_reader :params, :result
4
+
5
+ def self.call(params = {})
6
+ new(params).tap do |object|
7
+ object.make_request
8
+ object.package_result
9
+ end
10
+ end
11
+
12
+ def initialize(params)
13
+ @params = params
14
+ end
15
+
16
+ def make_request
17
+ http = Net::HTTP.new(request_url.host, request_url.port)
18
+ http.use_ssl = true
19
+ http.set_debug_output($stdout)
20
+ request = request_method_klass.new(request_url, request_headers)
21
+ request.body = request_params.to_json
22
+ @response = http.request(request)
23
+ end
24
+
25
+ def package_result
26
+ @result = { response: JSON.parse(@response.body), status_code: @response.code, success: success? }
27
+ end
28
+
29
+ def headers
30
+ {}
31
+ end
32
+
33
+ private
34
+
35
+ def request_params
36
+ {}
37
+ end
38
+
39
+ def request_headers
40
+ headers.merge({
41
+ authorization: "Bearer #{Bitport.configuration.access_token}"
42
+ })
43
+ end
44
+
45
+ def request_url
46
+ URI([Bitport::BASE_API_URL, endpoint].join('/'))
47
+ end
48
+
49
+ def success?
50
+ (@response.code.to_i / 100) == 2
51
+ end
52
+ end
53
+ end
54
+
55
+ require "bitport/token"
56
+ require "bitport/me"
57
+ require "bitport/folders"
58
+ # require "bitport/files"
59
+ require "bitport/search"
60
+ require "bitport/transfers"
@@ -0,0 +1,12 @@
1
+ module Bitport
2
+ class Config
3
+ attr_accessor :application_id, :secret, :user_code, :access_token
4
+
5
+ def initialize
6
+ @application_id = ''
7
+ @secret = ''
8
+ @user_code = ''
9
+ @access_token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6IjgxNzUxODY0ODgxZDFhODNjMzFiMTM2YWI2YzU2MTUwZjY4N2U3MWFlZjg5NmZhMTgwNDc2ZjZkNDNlNTA3MDAzOTlkZjVhMzUwYmNkNGUxIn0.eyJhdWQiOiIzNDYyNSIsImp0aSI6IjgxNzUxODY0ODgxZDFhODNjMzFiMTM2YWI2YzU2MTUwZjY4N2U3MWFlZjg5NmZhMTgwNDc2ZjZkNDNlNTA3MDAzOTlkZjVhMzUwYmNkNGUxIiwiaWF0IjoxNTc1MTQ1NDgyLCJuYmYiOjE1NzUxNDU0ODIsImV4cCI6MTczMjk5ODI4Miwic3ViIjoiMjI0MTE1OCIsInNjb3BlcyI6W119.GdrKmPRK8o7V37zjaA8ceoSbWNZSTJlhGtlkMLu122aBbqZiGQoxM4F9FAriNezMrgZjEabGN1cWph9sdxba1Xrxwk52wuF8994-Ers9hkXN_TlTMIAzw74Zauis2SDRAbSIhECRU27_zacZNqEZ2MkGqky_PU3nBWidH8TTMd0", "refresh_token"=>"def502006fde8d91eb7b892ba9aaba1601a7bcd096c62effb7c17eae54404e773da03e41caa785aa66622f29721add13127119643bbe57d4802de4a5aaebd0ced22b0d57338424930847127ce20f4256d2fa587b4944f96c1ee268c73c7627a3d242c7154f15b17b434e6b6f8a3140e3b7871afc399a2ae080c6bc5f7612d27eae1a4abc704f5a9fe84d3a275ae95f347a8a9b89cf262419160af08435320228f26522b608a5151fcc22218215601840337d2e85768c678832e26514b96ca4160ae3e036e7b52b6b0384eed147927699568a692b6bf035126cbf85b4b86aab17a7c61e97206c0f2a7906d41953f6863105b48d3b2c4d57e6287b1c2e72aff0f61d8e042153a804b9c89e8570c22a107cfc0a0c83e60469f504cfc4f345cda9860c9bdb7e00b9e68ab5fd6c8bcabd9940d1c7fbbfb075a486585a0acd7cc03c11a4cd6c4fc7e810e53019849c013673cbec56e7f39f3f22d80fce4c14b3e4afe973c323c0fe6aad38e81761'
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,4 @@
1
+ module Bitport
2
+ class InsufficientCredentialsError < StandardError
3
+ end
4
+ end
@@ -0,0 +1,38 @@
1
+ require 'rest-client'
2
+
3
+ module Bitport
4
+ class Files
5
+ def self.all
6
+ end
7
+
8
+ def self.find(file_code)
9
+ end
10
+
11
+ def self.destroy_by(file_code)
12
+ end
13
+
14
+ def self.destroy_all(file_codes)
15
+ end
16
+
17
+ def self.download(file_code)
18
+ end
19
+
20
+ def self.stream(file_code)
21
+ end
22
+
23
+ def self.stream_url(file_code)
24
+ end
25
+
26
+ def self.stream_information(file_code)
27
+ end
28
+
29
+ def self.subtitles(file_code)
30
+ end
31
+
32
+ def self.update(file_code)
33
+ end
34
+
35
+ def self.hls_playlist(file_code)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,21 @@
1
+ module Bitport
2
+ module Folders
3
+ class Create < Base
4
+ private
5
+
6
+ def request_params
7
+ {
8
+ name: params[:name]
9
+ }
10
+ end
11
+
12
+ def request_method_klass
13
+ Net::HTTP::Put
14
+ end
15
+
16
+ def endpoint
17
+ "cloud/#{params[:folder_code]}"
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,19 @@
1
+ module Bitport
2
+ module Folders
3
+ class Delete < Base
4
+ private
5
+
6
+ def request_params
7
+ {}
8
+ end
9
+
10
+ def request_method_klass
11
+ Net::HTTP::Delete
12
+ end
13
+
14
+ def endpoint
15
+ "cloud/#{params[:folder_code]}"
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+ module Bitport
2
+ module Folders
3
+ class Deletes < Base
4
+ private
5
+
6
+ def request_params
7
+ {
8
+ folders_codes: params[:folders_codes]
9
+ }
10
+ end
11
+
12
+ def request_method_klass
13
+ Net::HTTP::Post
14
+ end
15
+
16
+ def endpoint
17
+ "cloud/deletes"
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,19 @@
1
+ module Bitport
2
+ module Folders
3
+ class DownloadAsZip < Base
4
+ private
5
+
6
+ def request_params
7
+ {}
8
+ end
9
+
10
+ def request_method_klass
11
+ Net::HTTP::Get
12
+ end
13
+
14
+ def endpoint
15
+ "cloud/#{params[:folder_code]}/download-as-zip"
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,17 @@
1
+ module Bitport
2
+ module Folders
3
+ module Items
4
+ class List < Base
5
+ private
6
+
7
+ def request_method_klass
8
+ Net::HTTP::Get
9
+ end
10
+
11
+ def endpoint
12
+ "cloud/item/byPath"
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ module Bitport
2
+ module Folders
3
+ module Items
4
+ def self.list
5
+ List.call
6
+ end
7
+ end
8
+ end
9
+ end
10
+
11
+ require_relative './items/list'
@@ -0,0 +1,19 @@
1
+ module Bitport
2
+ module Folders
3
+ class List < Base
4
+ private
5
+
6
+ def request_params
7
+ {}
8
+ end
9
+
10
+ def request_method_klass
11
+ Net::HTTP::Get
12
+ end
13
+
14
+ def endpoint
15
+ "cloud/byPath"
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Bitport
2
+ module Folders
3
+ class Show < Base
4
+ private
5
+
6
+ def request_params
7
+ {}
8
+ end
9
+
10
+ def request_method_klass
11
+ Net::HTTP::Get
12
+ end
13
+
14
+ def endpoint
15
+ "cloud/#{params[:folder_code]}"
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,22 @@
1
+ module Bitport
2
+ module Folders
3
+ class Update < Base
4
+ private
5
+
6
+ def request_params
7
+ {
8
+ name: params[:name],
9
+ parent_code: params[:parent_code]
10
+ }
11
+ end
12
+
13
+ def request_method_klass
14
+ Net::HTTP::Put
15
+ end
16
+
17
+ def endpoint
18
+ "cloud/#{params[:folder_code]}"
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,17 @@
1
+ module Bitport
2
+ module Folders
3
+ module Videos
4
+ class DestroyPaused < Base
5
+ private
6
+
7
+ def request_method_klass
8
+ Net::HTTP::Delete
9
+ end
10
+
11
+ def endpoint
12
+ "cloud/paused-videos"
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Bitport
2
+ module Folders
3
+ module Videos
4
+ class List < Base
5
+ private
6
+
7
+ def request_method_klass
8
+ Net::HTTP::Get
9
+ end
10
+
11
+ def endpoint
12
+ "cloud/all-videos"
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Bitport
2
+ module Folders
3
+ module Videos
4
+ class Paused < Base
5
+ private
6
+
7
+ def request_method_klass
8
+ Net::HTTP::Get
9
+ end
10
+
11
+ def endpoint
12
+ "cloud/paused-videos"
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,21 @@
1
+ module Bitport
2
+ module Folders
3
+ module Videos
4
+ def self.list
5
+ List.call
6
+ end
7
+
8
+ def self.paused
9
+ Paused.call
10
+ end
11
+
12
+ def self.remove_paused
13
+ DestroyPaused.call
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ require_relative './videos/list'
20
+ require_relative './videos/paused'
21
+ require_relative './videos/destroy_paused'
@@ -0,0 +1,57 @@
1
+ module Bitport
2
+ module Folders
3
+ def self.list
4
+ List.call
5
+ end
6
+
7
+ def self.show(folder_code)
8
+ Show.call(folder_code: folder_code)
9
+ end
10
+
11
+ def self.delete(folder_code)
12
+ Delete.call(folder_code: folder_code)
13
+ end
14
+
15
+ def self.deletes(folder_codes)
16
+ Deletes.call(folder_codes: folder_codes)
17
+ end
18
+
19
+ def self.create(params)
20
+ Create.call(params)
21
+ end
22
+
23
+ def self.update(params)
24
+ Update.call(params)
25
+ end
26
+
27
+ def self.download_as_zip(folder_code)
28
+ DownloadAsZip.call(folder_code: folder_code)
29
+ end
30
+
31
+ def self.items
32
+ Items.list
33
+ end
34
+
35
+ def self.paused_videos
36
+ Videos.paused
37
+ end
38
+
39
+ def self.all_videos
40
+ Videos.list
41
+ end
42
+
43
+ def self.destroy_paused_videos
44
+ Videos.remove_paused
45
+ end
46
+ end
47
+ end
48
+
49
+ require_relative './folders/list'
50
+ require_relative './folders/show'
51
+ require_relative './folders/deletes'
52
+ require_relative './folders/delete'
53
+ require_relative './folders/create'
54
+ require_relative './folders/update'
55
+ require_relative './folders/download_as_zip'
56
+ require_relative './folders/videos'
57
+ require_relative './folders/items'
@@ -0,0 +1,19 @@
1
+ module Bitport
2
+ module Me
3
+ class Info < Base
4
+ private
5
+
6
+ def request_params
7
+ {}
8
+ end
9
+
10
+ def endpoint
11
+ "me"
12
+ end
13
+
14
+ def request_method_klass
15
+ Net::HTTP::Get
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Bitport
2
+ module Me
3
+ class Update < Base
4
+ private
5
+
6
+ def request_params
7
+ params
8
+ end
9
+
10
+ def endpoint
11
+ "me"
12
+ end
13
+
14
+ def request_method_klass
15
+ Net::HTTP::Put
16
+ end
17
+ end
18
+ end
19
+ end
data/lib/bitport/me.rb ADDED
@@ -0,0 +1,14 @@
1
+ module Bitport
2
+ module Me
3
+ def self.info
4
+ Info.call
5
+ end
6
+
7
+ def self.update(params = {})
8
+ Update.call(params)
9
+ end
10
+ end
11
+ end
12
+
13
+ require_relative './me/info'
14
+ require_relative './me/update'
@@ -0,0 +1,19 @@
1
+ module Bitport
2
+ module Search
3
+ class Perform < Base
4
+ private
5
+
6
+ def request_params
7
+ {}
8
+ end
9
+
10
+ def request_method_klass
11
+ Net::HTTP::Get
12
+ end
13
+
14
+ def endpoint
15
+ "search/#{params[:term]}"
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,9 @@
1
+ module Bitport
2
+ class Search
3
+ def self.perform(term)
4
+ Perform.call(term: term)
5
+ end
6
+ end
7
+ end
8
+
9
+ require_relative './search/perform'
@@ -0,0 +1,30 @@
1
+ module Bitport
2
+ module Token
3
+ class Fetch < Base
4
+ private
5
+
6
+ def request_headers
7
+ {
8
+ content_type: 'application/x-www-form-urlencoded'
9
+ }
10
+ end
11
+
12
+ def request_params
13
+ {
14
+ client_id: Bitport.configuration.application_id,
15
+ client_secret: Bitport.configuration.secret,
16
+ grant_type: 'code',
17
+ code: Bitport.configuration.user_code
18
+ }
19
+ end
20
+
21
+ def request_method_klass
22
+ Net::HTTP::Post
23
+ end
24
+
25
+ def endpoint
26
+ 'oauth2/access-token'
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,9 @@
1
+ module Bitport
2
+ module Token
3
+ def self.fetch
4
+ Fetch.call
5
+ end
6
+ end
7
+ end
8
+
9
+ require_relative './token/fetch'
@@ -0,0 +1,22 @@
1
+ module Bitport
2
+ module Transfers
3
+ class Create < Base
4
+ private
5
+
6
+ def request_params
7
+ {
8
+ torrent: params[:torrent],
9
+ folder_code: params[:folder_code]
10
+ }
11
+ end
12
+
13
+ def request_method_klass
14
+ Net::HTTP::Post
15
+ end
16
+
17
+ def endpoint
18
+ "transfers"
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,19 @@
1
+ module Bitport
2
+ module Transfers
3
+ class Destroy < Base
4
+ private
5
+
6
+ def request_params
7
+ {}
8
+ end
9
+
10
+ def request_method_klass
11
+ Net::HTTP::Delete
12
+ end
13
+
14
+ def endpoint
15
+ "transfers/#{params[:token]}"
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Bitport
2
+ module Transfers
3
+ class List < Base
4
+ private
5
+
6
+ def request_params
7
+ {}
8
+ end
9
+
10
+ def request_method_klass
11
+ Net::HTTP::Get
12
+ end
13
+
14
+ def endpoint
15
+ "transfers"
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Bitport
2
+ module Transfers
3
+ class Show < Base
4
+ private
5
+
6
+ def request_params
7
+ {}
8
+ end
9
+
10
+ def request_method_klass
11
+ Net::HTTP::Get
12
+ end
13
+
14
+ def endpoint
15
+ "transfers/#{params[:token]}"
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,24 @@
1
+ module Bitport
2
+ module Transfers
3
+ def self.all
4
+ List.call
5
+ end
6
+
7
+ def self.show(token)
8
+ Show.call(token: token)
9
+ end
10
+
11
+ def self.create(params)
12
+ Create.call(params)
13
+ end
14
+
15
+ def self.destroy(token)
16
+ Destroy.call(token: token)
17
+ end
18
+ end
19
+ end
20
+
21
+ require_relative './transfers/list'
22
+ require_relative './transfers/show'
23
+ require_relative './transfers/create'
24
+ require_relative './transfers/destroy'
@@ -0,0 +1,3 @@
1
+ module Bitport
2
+ VERSION = "0.0.1"
3
+ end
data/lib/bitport.rb ADDED
@@ -0,0 +1,32 @@
1
+ require "bitport/version"
2
+ require "bitport/errors"
3
+ require "bitport/config"
4
+ require "bitport/base"
5
+ require "net/http"
6
+ require "json"
7
+
8
+ module Bitport
9
+ BASE_API_URL = 'https://api.bitport.io/v2'
10
+
11
+ class << self
12
+ attr_accessor :configuration
13
+
14
+ def configure
15
+ self.configuration ||= Config.new
16
+ yield(configuration)
17
+ end
18
+
19
+ def get_access_token
20
+ raise InsufficientCredentialsError.new('Insufficient Credentials') unless all_required_credentials_present?
21
+ Token.fetch(configuration)
22
+ end
23
+
24
+ private
25
+
26
+ def all_required_credentials_present?
27
+ !configuration.application_id.empty? &&
28
+ !configuration.secret.empty? &&
29
+ !configuration.user_code.empty?
30
+ end
31
+ end
32
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bitport
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Aditya Kapoor
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-09-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: Download files to a secured cloud. Anonymously. Fast. Online.
56
+ email:
57
+ - adityakapoor.mait@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - lib/bitport.rb
63
+ - lib/bitport/base.rb
64
+ - lib/bitport/config.rb
65
+ - lib/bitport/errors.rb
66
+ - lib/bitport/files.rb
67
+ - lib/bitport/folders.rb
68
+ - lib/bitport/folders/create.rb
69
+ - lib/bitport/folders/delete.rb
70
+ - lib/bitport/folders/deletes.rb
71
+ - lib/bitport/folders/download_as_zip.rb
72
+ - lib/bitport/folders/items.rb
73
+ - lib/bitport/folders/items/list.rb
74
+ - lib/bitport/folders/list.rb
75
+ - lib/bitport/folders/show.rb
76
+ - lib/bitport/folders/update.rb
77
+ - lib/bitport/folders/videos.rb
78
+ - lib/bitport/folders/videos/destroy_paused.rb
79
+ - lib/bitport/folders/videos/list.rb
80
+ - lib/bitport/folders/videos/paused.rb
81
+ - lib/bitport/me.rb
82
+ - lib/bitport/me/info.rb
83
+ - lib/bitport/me/update.rb
84
+ - lib/bitport/search.rb
85
+ - lib/bitport/search/perform.rb
86
+ - lib/bitport/token.rb
87
+ - lib/bitport/token/fetch.rb
88
+ - lib/bitport/transfers.rb
89
+ - lib/bitport/transfers/create.rb
90
+ - lib/bitport/transfers/destroy.rb
91
+ - lib/bitport/transfers/list.rb
92
+ - lib/bitport/transfers/show.rb
93
+ - lib/bitport/version.rb
94
+ homepage: https://github.com/aditya-kapoor/bitport
95
+ licenses:
96
+ - MIT
97
+ metadata:
98
+ homepage_uri: https://github.com/aditya-kapoor/bitport
99
+ source_code_uri: https://github.com/aditya-kapoor/bitport
100
+ changelog_uri: https://github.com/aditya-kapoor/bitport/changelog.md
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubygems_version: 3.0.9
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: Ruby API wrapper around the Bitport.io online file download service.
120
+ test_files: []