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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f9eaa341ecf2f2c9523ca977ad805c6caa7205ba
4
- data.tar.gz: e8fae4d833420964454bdbbeba1269e92038e80f
3
+ metadata.gz: 17392d4bc25e085ef1205eb66b1b8614ab9fb3a6
4
+ data.tar.gz: 9e981ee20fb33eec987c54a05ffefeb81e44d76f
5
5
  SHA512:
6
- metadata.gz: 7d8d679f239efe70ac27e2166929b008fd5fb62fa08791f97041ce6a66a3ffd164a053bb48209055e60f32f293a10e273bf2889f6a362d1562232df879102dea
7
- data.tar.gz: c34fc9306f979e46889cb9261f5f2f3bbe0c7b68a440c24c4195c47451ef2fc1f954ac1f5b9acaf3c22f7236a83379333f27b3a36cbe0e308b0ce19469c8b244
6
+ metadata.gz: 8761472b02069c535a8541fe0ba92d6b85fbf359135d4ad3c13e8db327dc6f467ec9cc90f4deed7e6c9bd4b2c58fcf9b83093f03a22facb0c28028dd83d275fb
7
+ data.tar.gz: 9ca52bbba5623b7e89285b5aa0598fad4f0edaa81b85f1ae1e6ffd851a9a7b5240579ca1522e950b5b7159f7a46adde46be6f4690cbd9790d1219c3e11efb09e
@@ -6,7 +6,9 @@ http_interactions:
6
6
  body:
7
7
  encoding: US-ASCII
8
8
  string: ''
9
- headers: {}
9
+ headers:
10
+ user-agent:
11
+ - ReadOnce Gem/1.0.8
10
12
  response:
11
13
  status:
12
14
  code: 200
@@ -6,7 +6,9 @@ http_interactions:
6
6
  body:
7
7
  encoding: US-ASCII
8
8
  string: ''
9
- headers: {}
9
+ headers:
10
+ user-agent:
11
+ - ReadOnce Gem/1.0.8
10
12
  response:
11
13
  status:
12
14
  code: 200
@@ -12,7 +12,7 @@ http_interactions:
12
12
  accept:
13
13
  - "*/*"
14
14
  user-agent:
15
- - Ruby
15
+ - ReadOnce Gem/1.0.8
16
16
  response:
17
17
  status:
18
18
  code: 200
@@ -6,7 +6,9 @@ http_interactions:
6
6
  body:
7
7
  encoding: US-ASCII
8
8
  string: ''
9
- headers: {}
9
+ headers:
10
+ user-agent:
11
+ - ReadOnce Gem/1.0.8
10
12
  response:
11
13
  status:
12
14
  code: 200
@@ -6,7 +6,9 @@ http_interactions:
6
6
  body:
7
7
  encoding: US-ASCII
8
8
  string: ''
9
- headers: {}
9
+ headers:
10
+ user-agent:
11
+ - ReadOnce Gem/1.0.8
10
12
  response:
11
13
  status:
12
14
  code: 404
@@ -6,7 +6,9 @@ http_interactions:
6
6
  body:
7
7
  encoding: US-ASCII
8
8
  string: ''
9
- headers: {}
9
+ headers:
10
+ user-agent:
11
+ - ReadOnce Gem/1.0.8
10
12
  response:
11
13
  status:
12
14
  code: 200
@@ -1,3 +1,6 @@
1
1
  module Readonce
2
- VERSION = "1.0.8"
2
+ MAJOR_VERSION = 1
3
+ MINOR_VERSION = 0
4
+ PATCH_VERSION = 9
5
+ VERSION = "#{MAJOR_VERSION}.#{MINOR_VERSION}.#{PATCH_VERSION}"
3
6
  end
data/lib/readonce.rb CHANGED
@@ -1,9 +1,24 @@
1
- require 'readonce/version'
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
- response = HTTParty.post "#{BASE_URI}/create", body: data, headers: {'Content-type' => 'text/plain'}
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
- response = HTTParty.get "#{BASE_URI}/status/#{key}"
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
- response = HTTParty.get "#{BASE_URI}/status/#{key}"
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
- response = HTTParty.get "#{BASE_URI}/status/#{key}"
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: readonce
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8
4
+ version: 1.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robby Grossman