readonce 1.0.8 → 1.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/fixtures/vcr_cassettes/bag-read.yml +3 -1
- data/fixtures/vcr_cassettes/bag-unread.yml +3 -1
- data/fixtures/vcr_cassettes/create-file.yml +1 -1
- data/fixtures/vcr_cassettes/get-status.yml +3 -1
- data/fixtures/vcr_cassettes/key-does-not-exist.yml +3 -1
- data/fixtures/vcr_cassettes/key-exists.yml +3 -1
- data/lib/readonce/version.rb +4 -1
- data/lib/readonce.rb +24 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17392d4bc25e085ef1205eb66b1b8614ab9fb3a6
|
4
|
+
data.tar.gz: 9e981ee20fb33eec987c54a05ffefeb81e44d76f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8761472b02069c535a8541fe0ba92d6b85fbf359135d4ad3c13e8db327dc6f467ec9cc90f4deed7e6c9bd4b2c58fcf9b83093f03a22facb0c28028dd83d275fb
|
7
|
+
data.tar.gz: 9ca52bbba5623b7e89285b5aa0598fad4f0edaa81b85f1ae1e6ffd851a9a7b5240579ca1522e950b5b7159f7a46adde46be6f4690cbd9790d1219c3e11efb09e
|
data/lib/readonce/version.rb
CHANGED
data/lib/readonce.rb
CHANGED
@@ -1,9 +1,24 @@
|
|
1
|
-
|
1
|
+
require_relative 'readonce/version'
|
2
2
|
|
3
3
|
require 'httparty'
|
4
4
|
|
5
5
|
class ReadOnce
|
6
|
+
include HTTParty
|
6
7
|
BASE_URI = 'https://readonce-production.herokuapp.com'
|
8
|
+
USER_AGENT_HEADER = {'User-Agent' => "ReadOnce Gem/#{Readonce::VERSION}"}
|
9
|
+
base_uri BASE_URI
|
10
|
+
|
11
|
+
def self.exit_if_gem_outdated!
|
12
|
+
response = get '/minimum-ruby-client-version', headers: USER_AGENT_HEADER
|
13
|
+
major, minor, patch = response.body.split('.').map{|m| m.to_i}
|
14
|
+
|
15
|
+
if Readonce::MAJOR_VERSION < major || Readonce::MINOR_VERSION < minor || Readonce::PATCH_VERSION < patch
|
16
|
+
required_version = "#{major}.#{minor}.#{patch}"
|
17
|
+
puts "ERROR: Gem version is #{Readonce::VERSION}, but #{required_version} or later is now required."
|
18
|
+
puts 'Please run: gem install readonce'
|
19
|
+
exit
|
20
|
+
end
|
21
|
+
end
|
7
22
|
|
8
23
|
def self.from_key(key)
|
9
24
|
r = ReadOnce.new
|
@@ -12,7 +27,8 @@ class ReadOnce
|
|
12
27
|
end
|
13
28
|
|
14
29
|
def self.from_data(data)
|
15
|
-
|
30
|
+
self.exit_if_gem_outdated!
|
31
|
+
response = post '/create', body: data, headers: {'Content-type' => 'text/plain'}.merge(USER_AGENT_HEADER)
|
16
32
|
r = ReadOnce.new
|
17
33
|
r.instance_variable_set(:@key, response.body)
|
18
34
|
r
|
@@ -23,17 +39,20 @@ class ReadOnce
|
|
23
39
|
end
|
24
40
|
|
25
41
|
def read?
|
26
|
-
|
42
|
+
self.exit_if_gem_outdated!
|
43
|
+
response = self.class.get "/status/#{key}", headers: USER_AGENT_HEADER
|
27
44
|
!JSON.parse(response.body)['accessed_at'].nil?
|
28
45
|
end
|
29
46
|
|
30
47
|
def exists?
|
31
|
-
|
48
|
+
self.exit_if_gem_outdated!
|
49
|
+
response = self.class.get "/status/#{key}", headers: USER_AGENT_HEADER
|
32
50
|
response.code == 200
|
33
51
|
end
|
34
52
|
|
35
53
|
def status
|
36
|
-
|
54
|
+
self.exit_if_gem_outdated!
|
55
|
+
response = self.class.get "/status/#{key}", headers: USER_AGENT_HEADER
|
37
56
|
JSON.parse(response.body)
|
38
57
|
end
|
39
58
|
|