whos_got_dirt 0.0.3 → 0.0.4

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: 063529b54e6a2c0acb0ab21f1eb44bce5683afe8
4
- data.tar.gz: 428acf538ee358d701565695ca601078ba6db10b
3
+ metadata.gz: 1deb94dc54c2ea9e2f8b61d0b92b772b6a1319cf
4
+ data.tar.gz: 9c699bef6687a839ec92aebfc24d16f8f9b65f85
5
5
  SHA512:
6
- metadata.gz: 79d13ce720b98a1e70f7adabab7ad6797faeb304edaca55400a40ed9c3b679376be61d1b303cb75bdc4b67538c20be89c5d6ae149c49dc055c9c2d1563e31d3f
7
- data.tar.gz: 1d8433a1cf7d0b01784ddf2840baba3b93c3d515b0ce99e280eb74f54d25eee6d4db194cb230283f03a6bf3563c33590b520e4e072c1135458922b22e5feba85
6
+ metadata.gz: 17e0533d244d23aa69dd1459a4c1d8d8cede94f5e793d700c5f36d10fd24c5e3d1b9d7c6cba38fd23a946e7eb57e55ef00175224ca8b2cae0171dbdd272d2fe1
7
+ data.tar.gz: 28673a6d11fa8982803a02a148f9f3f9136005c31548af3dbda1b4083f40091bf842ab41f1ab5a80e4f29aa6bd22ed28b0f0f6dcd485706698cc9d28734a2a3b
@@ -56,6 +56,12 @@ module WhosGotDirt
56
56
  raise NotImplementedError
57
57
  end
58
58
 
59
+ # @abstract Subclass and override {#item_url} to return an item's URL when
60
+ # given a result
61
+ def item_url(result)
62
+ raise NotImplementedError
63
+ end
64
+
59
65
  # Returns the error message in the response body.
60
66
  #
61
67
  # @return [String] the error message in the response body
@@ -62,10 +62,23 @@ module WhosGotDirt
62
62
  #
63
63
  # @return [Array<Hash>] the results
64
64
  def to_a
65
- parsed_body['result'].map do |data|
65
+ parsed_body['result']['companies'].map do |_,data|
66
66
  Result.new('Entity', renderer.result(data), self).finalize!
67
67
  end
68
68
  end
69
+
70
+ # Returns an entity's URL.
71
+ #
72
+ # @param [Hash] result the rendered result
73
+ # @return [String] the entity's URL
74
+ def item_url(result)
75
+ query = CGI.parse(env.url.query.to_s)
76
+ url = "#{env.url.scheme}://#{env.url.host}#{env.url.path.sub(/\.json\z/, '')}/#{result['identifiers'][0]['identifier']}.json"
77
+ if query['key']
78
+ url += "?key=#{CGI.escape(query['key'][0].to_s)}"
79
+ end
80
+ url
81
+ end
69
82
  end
70
83
  end
71
84
  end
@@ -60,6 +60,15 @@ module WhosGotDirt
60
60
  Result.new('Entity', renderer.result(data), self).finalize!
61
61
  end
62
62
  end
63
+
64
+ # Returns an entity's URL.
65
+ #
66
+ # @param [Hash] result the rendered result
67
+ # @return [String] the entity's URL
68
+ def item_url(result)
69
+ query = CGI.parse(env.url.query.to_s)
70
+ "#{env.url.scheme}://#{env.url.host}/entity/#{result['identifiers'][0]['identifier']}.xml?_key=#{CGI.escape(query['_key'][0].to_s)}"
71
+ end
63
72
  end
64
73
  end
65
74
  end
@@ -56,6 +56,19 @@ module WhosGotDirt
56
56
  Result.new('Entity', renderer.result(data['company']), self).finalize!
57
57
  end
58
58
  end
59
+
60
+ # Returns an entity's URL.
61
+ #
62
+ # @param [Hash] result the rendered result
63
+ # @return [String] the entity's URL
64
+ def item_url(result)
65
+ query = CGI.parse(env.url.query.to_s)
66
+ url = "#{env.url.scheme}://#{env.url.host}/companies/#{result['jurisdiction_code']}/#{result['identifiers'][0]['identifier']}"
67
+ if query['api_token']
68
+ url += "?api_token=#{CGI.escape(query['api_token'][0].to_s)}"
69
+ end
70
+ url
71
+ end
59
72
  end
60
73
  end
61
74
  end
@@ -37,6 +37,15 @@ module WhosGotDirt
37
37
  end
38
38
  end
39
39
 
40
+ # Returns an entity's URL.
41
+ #
42
+ # @param [Hash] result the rendered result
43
+ # @return [String] the entity's URL
44
+ def item_url(result)
45
+ query = CGI.parse(env.url.query.to_s)
46
+ "#{env.url.scheme}://#{env.url.host}/index.php/api/entity?id=#{CGI.escape(result['identifiers'][0]['identifier'].to_s)}&key=#{CGI.escape(query['key'][0].to_s)}"
47
+ end
48
+
40
49
  def success?
41
50
  super && Array === parsed_body
42
51
  end
@@ -38,6 +38,15 @@ module WhosGotDirt
38
38
  Result.new('Entity', renderer.result(data), self).finalize!
39
39
  end
40
40
  end
41
+
42
+ # Returns an entity's URL.
43
+ #
44
+ # @param [Hash] result the rendered result
45
+ # @return [String] the entity's URL
46
+ def item_url(result)
47
+ query = CGI.parse(env.url.query.to_s)
48
+ "#{env.url.scheme}://#{env.url.host}/visualizacion/getEntityById?id=#{CGI.escape(result['identifiers'][0]['identifier'].to_s)}&entity=#{CGI.escape(query['entity'][0].to_s)}&user_key=#{CGI.escape(query['user_key'][0].to_s)}"
49
+ end
41
50
  end
42
51
  end
43
52
  end
@@ -36,6 +36,15 @@ module WhosGotDirt
36
36
  Result.new('List', renderer.result(data), self).finalize!
37
37
  end
38
38
  end
39
+
40
+ # Returns a list's URL.
41
+ #
42
+ # @param [Hash] result the rendered result
43
+ # @return [String] the list's URL
44
+ def item_url(result)
45
+ query = CGI.parse(env.url.query.to_s)
46
+ "#{env.url.scheme}://#{env.url.host}/list/#{result['identifiers'][0]['identifier']}.xml?_key=#{CGI.escape(query['_key'][0].to_s)}"
47
+ end
39
48
  end
40
49
  end
41
50
  end
@@ -28,6 +28,19 @@ module WhosGotDirt
28
28
  Result.new('List', renderer.result(data['corporate_grouping']), self).finalize!
29
29
  end
30
30
  end
31
+
32
+ # Returns a list's URL.
33
+ #
34
+ # @param [Hash] result the rendered result
35
+ # @return [String] the list's URL
36
+ def item_url(result)
37
+ query = CGI.parse(env.url.query.to_s)
38
+ url = "#{env.url.scheme}://#{env.url.host}/corporate_groupings/#{CGI.escape(result['name'].to_s)}"
39
+ if query['api_token']
40
+ url += "?api_token=#{CGI.escape(query['api_token'][0].to_s)}"
41
+ end
42
+ url
43
+ end
31
44
  end
32
45
  end
33
46
  end
@@ -60,6 +60,19 @@ module WhosGotDirt
60
60
  Result.new('Relation', renderer.result(data['officer']), self).finalize!
61
61
  end
62
62
  end
63
+
64
+ # Returns a relation's URL.
65
+ #
66
+ # @param [Hash] result the rendered result
67
+ # @return [String] the relation's URL
68
+ def item_url(result)
69
+ query = CGI.parse(env.url.query.to_s)
70
+ url = "#{env.url.scheme}://#{env.url.host}/officers/#{result['identifiers'][0]['identifier']}"
71
+ if query['api_token']
72
+ url += "?api_token=#{CGI.escape(query['api_token'][0].to_s)}"
73
+ end
74
+ url
75
+ end
63
76
  end
64
77
  end
65
78
  end
@@ -74,6 +74,15 @@ module WhosGotDirt
74
74
  Result.new('Relation', renderer.result(data), self).finalize!
75
75
  end
76
76
  end
77
+
78
+ # Returns a relation's URL.
79
+ #
80
+ # @param [Hash] result the rendered result
81
+ # @return [String] the relation's URL
82
+ def item_url(result)
83
+ query = CGI.parse(env.url.query.to_s)
84
+ "#{env.url.scheme}://#{env.url.host}/concession/#{result['identifiers'][0]['identifier']}?apikey=#{CGI.escape(query['apikey'][0].to_s)}"
85
+ end
77
86
  end
78
87
  end
79
88
  end
@@ -24,6 +24,17 @@ module WhosGotDirt
24
24
  @response = response
25
25
  end
26
26
 
27
+ # Adds an API URL for the result.
28
+ #
29
+ # @return [Hash] the result
30
+ def add_link!
31
+ result['links'] ||= []
32
+ result['links'] << {
33
+ 'url' => response.item_url(result),
34
+ 'note' => response.class.name.rpartition('::')[2],
35
+ }
36
+ end
37
+
27
38
  # Adds the requested URL as a source.
28
39
  #
29
40
  # @return [Hash] the result
@@ -98,6 +109,7 @@ module WhosGotDirt
98
109
  #
99
110
  # @return [Hash] the result
100
111
  def finalize!
112
+ add_link!
101
113
  add_source!
102
114
  validate!
103
115
  result
@@ -1,3 +1,3 @@
1
1
  module WhosGotDirt
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -29,6 +29,10 @@ module WhosGotDirt
29
29
  Result.new('Entity', renderer.result(data), self).finalize!
30
30
  end
31
31
  end
32
+
33
+ def item_url(result)
34
+ "https://api.example.com/item/#{result['identifiers'][0]['identifier']}"
35
+ end
32
36
  end
33
37
  end
34
38
 
@@ -100,6 +104,10 @@ module WhosGotDirt
100
104
  'identifier' => 'john-smith',
101
105
  'scheme' => 'ACME',
102
106
  }],
107
+ 'links' => [{
108
+ 'url' => 'https://api.example.com/item/john-smith',
109
+ 'note' => 'MyResponse',
110
+ }],
103
111
  'sources' => [{
104
112
  'url' => 'https://api.example.com/endpoint?name~=John+Smith',
105
113
  'note' => 'MyResponse',
@@ -112,6 +120,10 @@ module WhosGotDirt
112
120
  'identifier' => 'john-aaron-smith',
113
121
  'scheme' => 'ACME',
114
122
  }],
123
+ 'links' => [{
124
+ 'url' => 'https://api.example.com/item/john-aaron-smith',
125
+ 'note' => 'MyResponse',
126
+ }],
115
127
  'sources' => [{
116
128
  'url' => 'https://api.example.com/endpoint?name~=John+Smith',
117
129
  'note' => 'MyResponse',
data/spec/result_spec.rb CHANGED
@@ -20,7 +20,11 @@ module WhosGotDirt
20
20
  env = Faraday::Env.new
21
21
  env.url = 'https://api.example.com/endpoint?name~=John+Smith'
22
22
  env.body = '[{"fn":"John Smith","id":"john-smith"},{"fn":"John Aaron Smith","id":"john-aaron-smith"}]'
23
- Faraday::Response.new(env)
23
+ response = Faraday::Response.new(env)
24
+ def response.item_url(result)
25
+ "https://api.example.com/item/#{result['identifiers'][1]['identifier']}"
26
+ end
27
+ response
24
28
  end
25
29
 
26
30
  let :instance do
@@ -79,6 +83,10 @@ module WhosGotDirt
79
83
  'identifiers' => [{
80
84
  'identifier' => 'john-smith',
81
85
  }],
86
+ 'links' => [{
87
+ 'url' => 'https://api.example.com/item/john-smith',
88
+ 'note' => 'Response',
89
+ }],
82
90
  'sources' => [{
83
91
  'url' => 'https://api.example.com/endpoint?name~=John+Smith',
84
92
  'note' => 'Response',
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whos_got_dirt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - James McKinney
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-14 00:00:00.000000000 Z
11
+ date: 2016-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport