securitytrails 0.1.3 → 0.1.4

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: 37f4714cbaf589bc875b67400c353c2c9171e3c448ef7549a256748715e0f11e
4
- data.tar.gz: 9c4b17f6a50beffa18476e6c277666e7b26ce2fef2c2c5d189976bd583a5c487
3
+ metadata.gz: 44c325c548c7440852f81371215d2ed0c924138a6079d163a59b96a420cbf922
4
+ data.tar.gz: a5a154295f36ad0d411e3633eac96142d3066e11d2fd42282c76eb96602db42e
5
5
  SHA512:
6
- metadata.gz: df7a70cc8942cddc48f1037be64949072c4a468450d5838c537dcd28d7ae07479f46a3e888ed489a356260dfa94ba02dc5b4fe4e4e19b59f0ac556a267e45655
7
- data.tar.gz: d664ec3b675e95bc3cbccd16b43d48b5fb7d3fb36efa9ad75f602afca7ab3ab1db4bb925c04365ba7e06f749ab39a243311624cf0eb71de0d4afc421d1a6f293
6
+ metadata.gz: 2b2efa2c2f0e254f5b5736b7a2d96b0edbbaf20faceba31d289ae0675030e1e32855c40f1bc0c2787ce68e1517f4ad03d00ad2324a084f4bdb2af80ba496b344
7
+ data.tar.gz: b4707d84034420dc820d4a0cd9762d004187a133853bda53aa54b51e044c8033315112d9dee3a68a86b979acc3d1e3eb5a34c1f51f212000545f483db8b673da
@@ -10,6 +10,7 @@ module SecurityTrails
10
10
  HOST = "api.securitytrails.com"
11
11
  VERSION = 1
12
12
  URL = "https://#{HOST}/v#{VERSION}"
13
+ API_KEY_HEADER = "apikey"
13
14
 
14
15
  def initialize(api_key)
15
16
  @api_key = api_key
@@ -48,19 +49,19 @@ module SecurityTrails
48
49
 
49
50
  def get(path, params = {}, &block)
50
51
  url = url_for(path)
51
- params["apikey"] = api_key
52
52
  url.query = URI.encode_www_form(params)
53
53
 
54
54
  get = Net::HTTP::Get.new(url)
55
+ get.add_field(API_KEY_HEADER, api_key)
55
56
  request(get, &block)
56
57
  end
57
58
 
58
59
  def post(path, params = {}, &block)
59
60
  url = url_for(path)
60
- url.query = "apikey=#{api_key}"
61
61
 
62
62
  post = Net::HTTP::Post.new(url)
63
63
  post.body = params.is_a?(Hash) ? params.to_json : params.to_s
64
+ post.add_field(API_KEY_HEADER, api_key)
64
65
  request(post, &block)
65
66
  end
66
67
  end
@@ -3,5 +3,20 @@
3
3
  require "ostruct"
4
4
 
5
5
  module SecurityTrails
6
- class Response < OpenStruct; end
6
+ class Response < OpenStruct
7
+ def openstruct_to_hash(object, hash = {})
8
+ object.each_pair do |key, value|
9
+ hash[key] = case value
10
+ when OpenStruct then openstruct_to_hash(value)
11
+ when Array then value.map { |v| openstruct_to_hash(v) }
12
+ else value
13
+ end
14
+ end
15
+ hash
16
+ end
17
+
18
+ def to_h
19
+ openstruct_to_hash(self)
20
+ end
21
+ end
7
22
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SecurityTrails
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.4"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: securitytrails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manabu Niseki
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-11-01 00:00:00.000000000 Z
11
+ date: 2018-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler