platformcraft-filespot 0.1.0 → 0.1.1

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: ce9b8ca97b45d1bd725051781cab4895a77cbf9f
4
- data.tar.gz: 0bf5eebbdf1402e9668e90f92446c0186e508de4
3
+ metadata.gz: dcf14ef4db847c5acce86205463816c92e5253d7
4
+ data.tar.gz: 0dcf09bdcf0ec78c02f21f47b98655edf4297c64
5
5
  SHA512:
6
- metadata.gz: de9d88d716c115541d00fe96671c0b689556408c6c24a7fbbf3a43aa531de6d40a834e323b5c5e169d9858f477259b484e34d9991bfa0487b38f56fd4dc6d31a
7
- data.tar.gz: ab831422fcbeeeb6ec0baea3e0d391e792de277943e39dd23fa323b2aad7761317c42190e46c984cabd93aa87a8d137f2b4e8de6941de45d933ace4d3707ed2f
6
+ metadata.gz: 09b095787de758de0b9d3ff6bba0f84c3168f9ae28b249f102a17f6d563967aff25f4e2a048767a8be3c55dcf714bd955f65588e43fdcbeb2877521c2925f676
7
+ data.tar.gz: 38123ce0ad062ee4b7bd1c4ac6fed4bb54a4ca12adcc60f5ee6393462f2128a6210a4c9e091da6f9bb73f4c583e4c2b51cb56f4af05afe223ead91002d5a8142
@@ -5,10 +5,22 @@ module Filespot
5
5
  attr_reader :code, :status, :data
6
6
 
7
7
  def initialize(response)
8
- json_data = JSON.parse(response.body)
9
- @code = json_data.delete('code').to_i
10
- @status = json_data.delete('status')
11
- @data = json_data
8
+ if response.status == 200
9
+ json_data = JSON.parse(response.body)
10
+ @code = json_data.delete('code').to_i
11
+ @status = json_data.delete('status')
12
+ @data = json_data
13
+ else
14
+ return_error
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def return_error
21
+ @code = 500
22
+ @status = 'error'
23
+ @data = nil
12
24
  end
13
25
  end
14
26
  end
@@ -1,3 +1,3 @@
1
1
  module Filespot
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.1.1'.freeze
3
3
  end
@@ -0,0 +1,15 @@
1
+ {
2
+ "code": 200,
3
+ "files":["56ea7c4e534b44353536586c"],
4
+ "status": "success",
5
+ "task": {
6
+ "id": "57011e2a534b44741fc67880",
7
+ "category": "download",
8
+ "title": "Download abc.mp4",
9
+ "body": "Download success.",
10
+ "status": "Completed",
11
+ "time_start": "03.04.2016T16:44:10",
12
+ "time_finish": "03.04.2016T16:44:11",
13
+ "lock": false
14
+ }
15
+ }
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe Filespot::Download do
4
+ describe 'Download' do
5
+ context 'get_download_task' do
6
+ it 'success' do
7
+ stub_get('/download_tasks/57011e2a534b44741fc67880', 'download_tasks_id.json')
8
+ task = Filespot::Client.get_download_task('57011e2a534b44741fc67880')
9
+ expect(task.id).to eq '57011e2a534b44741fc67880'
10
+ end
11
+
12
+ it 'task_id not found' do
13
+ stub_request(:get, /api/).to_return(status: 500, body: nil)
14
+ task = Filespot::Client.get_download_task('nil')
15
+ expect(task).to eq nil
16
+ end
17
+ end
18
+ end
19
+ end
@@ -2,20 +2,8 @@ require 'spec_helper'
2
2
 
3
3
  describe Filespot::Client do
4
4
  describe 'Objects' do
5
- before do
6
- allow(Time).to receive(:now).and_return(1450342665)
7
-
8
- Filespot.configure do |config|
9
- config.url = 'api.platformcraft.ru'
10
- config.version = '1'
11
- config.apiuserid = 'test'
12
- config.apikey = 'APIUserKey'
13
- end
14
- end
15
-
16
5
  it '.get_objects' do
17
- uri = 'http://api.platformcraft.ru/1/objects?apiuserid=test&hash=46c5500379d2c09c6f8972c7fd79c27fd7ebf0dd0ab47833a034fd613a4f4d93&timestamp=1450342665'
18
- stub_get(uri, 'objects.json')
6
+ stub_get('/objects', 'objects.json')
19
7
  objects = Filespot::Client.get_objects
20
8
  expect(objects.count).to eq 2
21
9
  end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe Filespot::Response do
4
+ context 'errors' do
5
+ let(:response) { double('response') }
6
+
7
+ it 'nil if server error' do
8
+ allow(response).to receive(:status).and_return(500)
9
+ expect(Filespot::Response.new(response).data).to be_nil
10
+ end
11
+ end
12
+ end
data/spec/spec_helper.rb CHANGED
@@ -9,11 +9,23 @@ RSpec.configure do |config|
9
9
  config.mock_with :rspec do |mocks|
10
10
  mocks.verify_partial_doubles = true
11
11
  end
12
+
13
+ config.before(:each) do
14
+ allow(Time).to receive(:now).and_return(1450342665)
15
+
16
+ Filespot.configure do |config|
17
+ config.url = 'api.platformcraft.ru'
18
+ config.version = '1'
19
+ config.apiuserid = 'test'
20
+ config.apikey = 'APIUserKey'
21
+ end
22
+ end
12
23
  end
13
24
 
14
- def stub_get(uri, fixture_name)
25
+ def stub_get(api_method, fixture_name)
15
26
  encoding = 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3'
16
27
  agent = 'Faraday v0.9.2'
28
+ uri = /api.platformcraft.ru\/1/
17
29
  stub_request(:get, uri).with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=> encoding, 'User-Agent'=> agent}).to_return(status: 200, body: fixture(fixture_name), headers: {})
18
30
  end
19
31
 
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.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - droff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-15 00:00:00.000000000 Z
11
+ date: 2016-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -85,10 +85,13 @@ files:
85
85
  - lib/filespot/response.rb
86
86
  - lib/filespot/version.rb
87
87
  - platformcraft-filespot.gemspec
88
+ - spec/fixtures/download_tasks_id.json
88
89
  - spec/fixtures/objects.json
90
+ - spec/lib/client/download_spec.rb
89
91
  - spec/lib/client/objects_spec.rb
90
92
  - spec/lib/client_spec.rb
91
93
  - spec/lib/digest_spec.rb
94
+ - spec/lib/response_spec.rb
92
95
  - spec/spec_helper.rb
93
96
  homepage: ''
94
97
  licenses: []
@@ -109,8 +112,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
112
  version: '0'
110
113
  requirements: []
111
114
  rubyforge_project:
112
- rubygems_version: 2.5.0
115
+ rubygems_version: 2.6.2
113
116
  signing_key:
114
117
  specification_version: 4
115
118
  summary: http://doc.platformcraft.ru/filespot/api/
116
- test_files: []
119
+ test_files:
120
+ - spec/fixtures/download_tasks_id.json
121
+ - spec/fixtures/objects.json
122
+ - spec/lib/client/download_spec.rb
123
+ - spec/lib/client/objects_spec.rb
124
+ - spec/lib/client_spec.rb
125
+ - spec/lib/digest_spec.rb
126
+ - spec/lib/response_spec.rb
127
+ - spec/spec_helper.rb