timdex-ruby 0.1.2 → 0.1.3

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
  SHA256:
3
- metadata.gz: 632247caaf96075ed73f720181a04aef35958cf967a4a27f002fdbd824b36674
4
- data.tar.gz: 159e300352dc8904d9d921aa582d271fd1734b665722f9be3b4cb4b799b7bc47
3
+ metadata.gz: 766f14530e8558bf6ed0268b8cf7f97925c7fddb694b5ada5f5821f16f410c83
4
+ data.tar.gz: d5b6ecf6a3647174648b0953365a5d29fc26b17cb7237fe9740e482069b72b6e
5
5
  SHA512:
6
- metadata.gz: 5af7775bfe8c41fbc09d9872eb6bb31810ef33bfc35db1ba1b323d8d09f002e31021762aa17828fb85e9442c0e6901b6dcdb6beeedfe8ed227a1eb8562245dc6
7
- data.tar.gz: 9b3e6c3c49116596b465a02505dc8c2865d34bbcd395f876f0ec23f02440c82b53288a5ca97f6db81481c5a8b2c2aa405c3e0eaf207f5e295b3dd5583fdbf628
6
+ metadata.gz: cb5badf11701694e0190147506ef7127e2c04c1c1068abc309b860fbcc8c7509f05c9d5ed74ddb8ef91eeb5a5f5ac6490f45fa1d3250f67be297cf4934b90f25
7
+ data.tar.gz: fa4d6fc5f2614fa7978f56475b9ce6f7146b055a4522342dfef0ff251dec93b55b18f3e2a5c6567b382f6635ec6c29855a798cd37bb73aff507db20b5247c87b
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- timdex-ruby (0.1.0)
4
+ timdex-ruby (0.1.3)
5
5
  faraday (~> 0)
6
6
 
7
7
  GEM
@@ -10,7 +10,6 @@ GEM
10
10
  byebug (5.0.0)
11
11
  columnize (= 0.9.0)
12
12
  columnize (0.9.0)
13
- dotenv (2.7.1)
14
13
  faraday (0.15.4)
15
14
  multipart-post (>= 1.2, < 3)
16
15
  jwt (2.1.0)
@@ -24,7 +23,6 @@ PLATFORMS
24
23
  DEPENDENCIES
25
24
  bundler (~> 2)
26
25
  byebug (~> 5.0)
27
- dotenv
28
26
  jwt
29
27
  minitest (~> 5.0)
30
28
  rake (~> 10.0)
@@ -6,32 +6,35 @@ require 'json'
6
6
  require 'jwt'
7
7
 
8
8
  # Timdex modules wraps interaction with the public TIMDEX API
9
- module Timdex
9
+ class Timdex
10
10
  TIMDEX_BASE = 'https://timdex.mit.edu/api'.freeze
11
11
  TIMDEX_VERSION = '/v1'.freeze
12
12
  TIMDEX_URL = TIMDEX_BASE + TIMDEX_VERSION
13
- TIMDEX_USER = ENV['TIMDEX_USER']
14
- TIMDEX_PASS = ENV['TIMDEX_PASS']
15
13
 
16
- def self.setup
14
+ def initialize(username, password)
15
+ @username = username
16
+ @password = password
17
+ end
18
+
19
+ def setup
17
20
  @conn = Faraday.new(url: TIMDEX_URL)
18
21
  end
19
22
 
20
- def self.ping
23
+ def ping
21
24
  setup
22
25
  response = @conn.get('/api/v1/ping')
23
26
  JSON.parse(response.body)
24
27
  end
25
28
 
26
- def self.auth
29
+ def auth
27
30
  setup
28
- @conn.basic_auth(TIMDEX_USER, TIMDEX_PASS)
31
+ @conn.basic_auth(@username, @password)
29
32
  response = @conn.get('/api/v1/auth')
30
33
 
31
34
  @jwt = JSON.parse(response.body)
32
35
  end
33
36
 
34
- def self.search(term)
37
+ def search(term)
35
38
  setup
36
39
  auth unless validate_jwt
37
40
  @conn.token_auth(@jwt)
@@ -43,7 +46,7 @@ module Timdex
43
46
  parse_results(json_results, response.status)
44
47
  end
45
48
 
46
- def self.retrieve(id)
49
+ def retrieve(id)
47
50
  setup
48
51
  auth unless validate_jwt
49
52
  @conn.token_auth(@jwt)
@@ -55,7 +58,7 @@ module Timdex
55
58
  parse_record(json_result, response.status)
56
59
  end
57
60
 
58
- def self.parse_record(json_result, status)
61
+ def parse_record(json_result, status)
59
62
  response = {}
60
63
  response['status'] = status
61
64
  response['record'] = Record.new(json_result)
@@ -63,7 +66,7 @@ module Timdex
63
66
  response
64
67
  end
65
68
 
66
- def self.parse_results(json_results, status)
69
+ def parse_results(json_results, status)
67
70
  results = {}
68
71
  results['status'] = status
69
72
  results['hits'] = json_results['hits']
@@ -75,7 +78,7 @@ module Timdex
75
78
  results
76
79
  end
77
80
 
78
- def self.validate_jwt
81
+ def validate_jwt
79
82
  return false unless @jwt
80
83
 
81
84
  decoded_token = JWT.decode(@jwt, nil, false)
@@ -1,3 +1,3 @@
1
- module Timdex
2
- VERSION = "0.1.2"
1
+ class Timdex
2
+ VERSION = "0.1.3"
3
3
  end
@@ -22,7 +22,6 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.add_development_dependency "bundler", "~> 2"
24
24
  spec.add_development_dependency "byebug", "~> 5.0"
25
- spec.add_development_dependency "dotenv"
26
25
  spec.add_development_dependency "jwt"
27
26
  spec.add_development_dependency "minitest", "~> 5.0"
28
27
  spec.add_development_dependency "rake", "~> 10.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timdex-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Prevost
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-03-25 00:00:00.000000000 Z
11
+ date: 2019-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '5.0'
41
- - !ruby/object:Gem::Dependency
42
- name: dotenv
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: jwt
57
43
  requirement: !ruby/object:Gem::Requirement