platformcraft-filespot 0.1.4 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 35dccadd089a759ce2a50795b5732e8799662c7d
4
- data.tar.gz: 1b0981f71db5ca94c4a4a33e8bc86c3df2b8b394
3
+ metadata.gz: f3cbc70d020bcd62346f1726886acc00a20b4a2e
4
+ data.tar.gz: cdb832f47944d0f0378c0678de16da3f1d6679ad
5
5
  SHA512:
6
- metadata.gz: db1b43004260f73c12c3563fb0e65d8edb95a314676c2968c194e0b08fecc2fad54a954e42abe34a98cae83c1c1d37d0a23e4c2858d26ba1f3ee6b3717ae97e1
7
- data.tar.gz: a77f09f9c38d0ae29bc09a49a9655431cd09db38e1e2a105103c56cc64e4e9592199641e8b4d323c456af1c72c67d4319cff988313bfb6267106bc587a41cc76
6
+ metadata.gz: 975d1d2ba3f209d8c98470dfb7ccb2a1aacaa0fe6c849fcafdb196ef691da914f50efeee8de72e708a95e64294beee93a42db8d3c6fc3649e6b69ac8453a629c
7
+ data.tar.gz: c3c7e031f6cfa2a79943e5f793f474b723d8fc3e7578ea42d90d456bd3c3e002c20821616e2fd54ab8fb3365625d8e43fb1fe297a9f49a3d2226248ad1a2bd6f
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  Gemfile.lock
2
2
  *.gem
3
+ doc
@@ -1,5 +1,4 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9
4
3
  - 2.1
5
4
  - 2.2
@@ -5,6 +5,8 @@ require 'filespot/request'
5
5
  require 'filespot/response'
6
6
  require 'filespot/client'
7
7
 
8
+ ##
9
+ # Filespot gem module
8
10
  module Filespot
9
11
  extend Configuration
10
12
  end
@@ -2,6 +2,8 @@ require 'filespot/client/objects'
2
2
  require 'filespot/client/download'
3
3
 
4
4
  module Filespot
5
+ ##
6
+ # Client class provides a communication with API by methods
5
7
  class Client
6
8
  extend Objects
7
9
  extend Download
@@ -1,11 +1,17 @@
1
1
  module Filespot
2
+ ##
3
+ # Download module wraps methods with `/download` resource[http://doc.platformcraft.ru/filespot/api/#download]
2
4
  module Download
5
+ # POST /download
6
+ # returns task_id
3
7
  def post_download(url, path = nil)
4
8
  res = Response.new(Request.post("/download", {}, { url: url, path: path }))
5
9
  return nil unless res.code == 200
6
10
  res.data['task_id']
7
11
  end
8
12
 
13
+ # GET /download_tasks
14
+ # returns tasks list
9
15
  def get_download_tasks
10
16
  res = Response.new(Request.get("/download_tasks"))
11
17
  return [] unless res.code == 200
@@ -16,21 +22,29 @@ module Filespot
16
22
  arr
17
23
  end
18
24
 
25
+ # GET /download_tasks/{:task_id}
26
+ # returns task data
19
27
  def get_download_task(task_id)
20
28
  res = Response.new(Request.get("/download_tasks/#{task_id}"))
21
29
  return nil unless res.code == 200
22
30
  Task.new(res.data['task'], res.data['files'])
23
31
  end
24
32
 
33
+ # DELETE /download_tasks/{:task_id}
34
+ # returns removal status
25
35
  def delete_download_task(task_id)
26
36
  res = Response.new(Request.delete("/download_tasks/#{task_id}"))
27
37
  res
28
38
  end
29
39
  end
30
40
 
41
+ ##
42
+ # Task class provides task as object
31
43
  class Task
44
+ # files data
32
45
  attr_reader :files
33
46
 
47
+ # creates object
34
48
  def initialize(data, files = [])
35
49
  data.each { |k, v| define_singleton_method(k.to_sym) { v } }
36
50
  @files = files
@@ -1,9 +1,9 @@
1
1
  module Filespot
2
+ ##
3
+ # Objects module wraps methods with `/objects` resource[http://doc.platformcraft.ru/filespot/api/#objects]
2
4
  module Objects
3
- def exists?(path)
4
- !!get_object_by_path(path)
5
- end
6
-
5
+ # GET /objects
6
+ # returns an objects list
7
7
  def get_objects(folder=nil)
8
8
  res = Response.new(Request.get("/objects", folder: folder))
9
9
  return [] unless res.code == 200
@@ -14,12 +14,18 @@ module Filespot
14
14
  arr
15
15
  end
16
16
 
17
+ # GET /objects/{:object_id}
18
+ # returns an object
17
19
  def get_object(object_id)
18
20
  res = Response.new(Request.get("/objects/#{object_id}"))
19
21
  return nil unless res.code == 200
20
22
  Object.new(res.data['object'])
21
23
  end
22
24
 
25
+ # POST /objects
26
+ # * +file+ - file path(*required*)
27
+ # * +name+ - name that will be stored in API service
28
+ # returns a file info
23
29
  def post_object(file, name = nil)
24
30
  file_io = Faraday::UploadIO.new(file, 'application/octet-stream')
25
31
  res = Response.new(Request.post("/objects", {}, { file: file_io, name: name }))
@@ -28,28 +34,44 @@ module Filespot
28
34
  Object.new(res.data['object'])
29
35
  end
30
36
 
37
+ # DELETE /objects/{:object_id}
38
+ # returns removal status
31
39
  def delete_object(object_id)
32
40
  res = Response.new(Request.delete("/objects/#{object_id}"))
33
41
  res
34
42
  end
35
43
 
44
+ # deletes object which has been found by path
36
45
  def delete_object_by_path(path)
37
- object = get_object_by_path path
46
+ object = get_object_by_path(path)
38
47
  return delete_object(object.id) if object
48
+
39
49
  nil
40
50
  end
41
51
 
52
+ # GET /objects/{:path}
53
+ # returns an objects list
42
54
  def get_object_by_path(path)
43
55
  full_path = path[0] == '/' ? path : "/#{path}"
44
- folder = File.dirname full_path
56
+ folder = File.dirname(full_path)
57
+
45
58
  get_objects(folder).each do |object|
46
59
  return object if object.path == full_path
47
60
  end
61
+
48
62
  nil
49
63
  end
64
+
65
+ # checks if object exists
66
+ def exists?(path)
67
+ !!get_object_by_path(path)
68
+ end
50
69
  end
51
70
 
71
+ # Object class provides API object as ruby object
52
72
  class Object
73
+
74
+ # creates object
53
75
  def initialize(data)
54
76
  data.each { |k, v| define_singleton_method(k.to_sym) { v } }
55
77
  end
@@ -1,18 +1,35 @@
1
1
  module Filespot
2
+
3
+ ##
4
+ # Configuration module provides gem settings
5
+ #
6
+ # Filespot.configure do |config|
7
+ # config.url = 'api.platformcraft.ru'
8
+ # config.version = 1
9
+ # config.apikey = '12345'
10
+ # config.apiuserid = '12345'
11
+ # end
12
+ #
2
13
  module Configuration
14
+ # default API url
3
15
  API_URL = 'api.platformcraft.ru'
16
+ #default API version
4
17
  API_VERSION = 1
5
18
 
19
+ # options
6
20
  OPTIONS = [
7
21
  :url, :version, :apiuserid, :apikey
8
22
  ].freeze
9
23
 
24
+ # settings attributes
10
25
  attr_accessor *OPTIONS
11
26
 
27
+ # invoke module
12
28
  def self.extended(base)
13
29
  base.init
14
30
  end
15
31
 
32
+ # set default params
16
33
  def init
17
34
  self.url = API_URL
18
35
  self.version = API_VERSION
@@ -20,6 +37,7 @@ module Filespot
20
37
  self.apikey = nil
21
38
  end
22
39
 
40
+ # configure with gem settings
23
41
  def configure
24
42
  yield self
25
43
  end
@@ -2,7 +2,11 @@ require 'openssl'
2
2
  require 'base64'
3
3
 
4
4
  module Filespot
5
+ ##
6
+ # Digest class provides some encryption features
5
7
  class Digest
8
+
9
+ # generates HMAC[https://en.wikipedia.org/wiki/Hash-based_message_authentication_code]
6
10
  def self.hmac(http_method, uri)
7
11
  data = "#{http_method.upcase}+#{URI.decode(uri).gsub(/\Ahttps?:\/\//, '')}"
8
12
  OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), Filespot.apikey, data)
@@ -2,18 +2,36 @@ require 'faraday'
2
2
  require 'open-uri'
3
3
 
4
4
  module Filespot
5
+ ##
6
+ # Request class wraps HTTP-verbs
5
7
  class Request
6
8
 
9
+ # GET
10
+ #
11
+ # * +api_method+ - API method name
12
+ # * +uri_params+ - contains API method params
7
13
  def self.get(api_method = '', uri_params = {})
8
14
  uri = api_uri('GET', api_method, uri_params)
9
15
  connection(uri).get(uri.query)
10
16
  end
11
17
 
18
+ # POST
19
+ #
20
+ # * +api_method+ - API method name
21
+ # * +uri_params+ - contains API method params
22
+ # * +post_params+ - contains API post params
23
+ #
24
+ # === Example
25
+ # Request.post("/objects", {}, { file: file_io, name: name })
12
26
  def self.post(api_method = '', uri_params = {}, post_params = {})
13
27
  uri = api_uri('POST', api_method, uri_params)
14
28
  connection(uri).post(uri.query, post_params)
15
29
  end
16
30
 
31
+ # DELETE
32
+ #
33
+ # * +api_method+ - API method name
34
+ # * +uri_params+ - contains API method params
17
35
  def self.delete(api_method = '', uri_params = {})
18
36
  uri = api_uri('DELETE', api_method, uri_params)
19
37
  connection(uri).delete(uri.query)
@@ -1,9 +1,19 @@
1
1
  require 'json'
2
2
 
3
3
  module Filespot
4
+ ##
5
+ # Response class provides API response
4
6
  class Response
5
- attr_reader :code, :status, :data
7
+ # HTTP code
8
+ attr_reader :code
6
9
 
10
+ # response status
11
+ attr_reader :status
12
+
13
+ # response data in JSON format
14
+ attr_reader :data
15
+
16
+ # creates response, checks errors and provides data if success
7
17
  def initialize(response)
8
18
  return error if response.status == 500
9
19
 
@@ -1,3 +1,4 @@
1
1
  module Filespot
2
- VERSION = '0.1.4'.freeze
2
+ # gem version
3
+ VERSION = '0.1.5'.freeze
3
4
  end
@@ -6,7 +6,7 @@ Gem::Specification.new do |gem|
6
6
  gem.email = "adroff@gmail.com"
7
7
  gem.description = "gem provides platformcraft filespot api"
8
8
  gem.summary = "http://doc.platformcraft.ru/filespot/api/"
9
- gem.homepage = ""
9
+ gem.homepage = "https://github.com/droff/platformcraft-filespot"
10
10
 
11
11
  gem.add_development_dependency 'rake'
12
12
  gem.add_development_dependency 'rspec'
@@ -24,21 +24,26 @@ RSpec.configure do |config|
24
24
  end
25
25
  end
26
26
 
27
+ def uri
28
+ /api.platformcraft.ru\/1/
29
+ end
30
+
31
+ def headers
32
+ {
33
+ 'Accept'=>'*/*',
34
+ 'Accept-Encoding'=> 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
35
+ 'User-Agent'=> /Faraday/
36
+ }
37
+ end
38
+
27
39
  def stub_get(api_method, fixture_name)
28
- encoding = 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3'
29
- agent = 'Faraday v0.9.2'
30
- uri = /api.platformcraft.ru\/1/
31
- stub_request(:get, uri).with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=> encoding, 'User-Agent'=> agent}).to_return(status: 200, body: fixture(fixture_name), headers: {})
40
+ stub_request(:get, uri).with(headers: headers).to_return(status: 200, body: fixture(fixture_name), headers: {})
32
41
  end
33
42
 
34
43
  def stub_post(api_method, fixture_name)
35
- encoding = 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3'
36
- agent = 'Faraday v0.9.2'
37
- uri = /api.platformcraft.ru\/1/
38
44
  stub_request(:post, uri).with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=> encoding, 'User-Agent'=> agent}).to_return(status: 200, body: fixture(fixture_name), headers: {})
39
45
  end
40
46
 
41
-
42
47
  def fixture_path
43
48
  File.expand_path("../fixtures", __FILE__)
44
49
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: platformcraft-filespot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - droff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-15 00:00:00.000000000 Z
11
+ date: 2016-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -113,7 +113,7 @@ files:
113
113
  - spec/lib/digest_spec.rb
114
114
  - spec/lib/response_spec.rb
115
115
  - spec/spec_helper.rb
116
- homepage: ''
116
+ homepage: https://github.com/droff/platformcraft-filespot
117
117
  licenses: []
118
118
  metadata: {}
119
119
  post_install_message:
@@ -132,19 +132,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
132
  version: '0'
133
133
  requirements: []
134
134
  rubyforge_project:
135
- rubygems_version: 2.6.2
135
+ rubygems_version: 2.6.8
136
136
  signing_key:
137
137
  specification_version: 4
138
138
  summary: http://doc.platformcraft.ru/filespot/api/
139
- test_files:
140
- - spec/fixtures/download_tasks.json
141
- - spec/fixtures/download_tasks_id.json
142
- - spec/fixtures/objects.json
143
- - spec/fixtures/objects_id.json
144
- - spec/fixtures/objects_post.json
145
- - spec/lib/client/download_spec.rb
146
- - spec/lib/client/objects_spec.rb
147
- - spec/lib/client_spec.rb
148
- - spec/lib/digest_spec.rb
149
- - spec/lib/response_spec.rb
150
- - spec/spec_helper.rb
139
+ test_files: []