whos_got_dirt 0.0.2 → 0.0.3

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.
@@ -0,0 +1,57 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.littlesis.org/entities.xml?q=bar
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.1
12
+ response:
13
+ status:
14
+ code: 401
15
+ message:
16
+ headers:
17
+ server:
18
+ - cloudflare-nginx
19
+ date:
20
+ - Sun, 10 Jan 2016 23:54:18 GMT
21
+ content-type:
22
+ - text/html; charset=utf-8
23
+ transfer-encoding:
24
+ - chunked
25
+ connection:
26
+ - close
27
+ set-cookie:
28
+ - __cfduid=d0a1f180fbcab07f10a20a0e51d9152601452470058; expires=Mon, 09-Jan-17
29
+ 23:54:18 GMT; path=/; domain=.littlesis.org; HttpOnly, symfony=rjsiompvljpg9goqudp16ina83;
30
+ path=/
31
+ x-powered-by:
32
+ - PHP/5.5.9-1ubuntu4.6
33
+ expires:
34
+ - Thu, 19 Nov 1981 08:52:00 GMT
35
+ cache-control:
36
+ - no-store, no-cache, must-revalidate, post-check=0, pre-check=0
37
+ pragma:
38
+ - no-cache
39
+ www-authenticate:
40
+ - Your request must include a query parameter named "_key" with a valid API
41
+ key value. To obtain an API key, visit http://api.littlesis.org/register
42
+ vary:
43
+ - Accept-Encoding
44
+ access-control-allow-origin:
45
+ - "*"
46
+ cf-ray:
47
+ - 262c4e69e5463fa7-YUL
48
+ body:
49
+ encoding: UTF-8
50
+ string: |-
51
+ <?xml version="1.0" encoding="UTF-8"?>
52
+ <Response>
53
+ Your request must include a query parameter named "_key" with a valid API key value. To obtain an API key, visit http://api.littlesis.org/register.
54
+ </Response>
55
+ http_version:
56
+ recorded_at: Sun, 10 Jan 2016 23:54:18 GMT
57
+ recorded_with: VCR 3.0.1
@@ -0,0 +1,57 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.littlesis.org/lists.xml?q=united
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.1
12
+ response:
13
+ status:
14
+ code: 401
15
+ message:
16
+ headers:
17
+ server:
18
+ - cloudflare-nginx
19
+ date:
20
+ - Sun, 10 Jan 2016 23:54:54 GMT
21
+ content-type:
22
+ - text/html; charset=utf-8
23
+ transfer-encoding:
24
+ - chunked
25
+ connection:
26
+ - close
27
+ set-cookie:
28
+ - __cfduid=df94c524808fd39878295eeaf1d4bd7c81452470094; expires=Mon, 09-Jan-17
29
+ 23:54:54 GMT; path=/; domain=.littlesis.org; HttpOnly, symfony=q9culrvo85c6qrk56or8vo0eq3;
30
+ path=/
31
+ x-powered-by:
32
+ - PHP/5.5.9-1ubuntu4.6
33
+ expires:
34
+ - Thu, 19 Nov 1981 08:52:00 GMT
35
+ cache-control:
36
+ - no-store, no-cache, must-revalidate, post-check=0, pre-check=0
37
+ pragma:
38
+ - no-cache
39
+ www-authenticate:
40
+ - Your request must include a query parameter named "_key" with a valid API
41
+ key value. To obtain an API key, visit http://api.littlesis.org/register
42
+ vary:
43
+ - Accept-Encoding
44
+ access-control-allow-origin:
45
+ - "*"
46
+ cf-ray:
47
+ - 262c4f4b1d493fa1-YUL
48
+ body:
49
+ encoding: UTF-8
50
+ string: |-
51
+ <?xml version="1.0" encoding="UTF-8"?>
52
+ <Response>
53
+ Your request must include a query parameter named "_key" with a valid API key value. To obtain an API key, visit http://api.littlesis.org/register.
54
+ </Response>
55
+ http_version:
56
+ recorded_at: Sun, 10 Jan 2016 23:54:54 GMT
57
+ recorded_with: VCR 3.0.1
@@ -0,0 +1,37 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://www.openduka.org/index.php/api/search?term=the
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.1
12
+ response:
13
+ status:
14
+ code: 200
15
+ message:
16
+ headers:
17
+ date:
18
+ - Mon, 11 Jan 2016 01:50:10 GMT
19
+ server:
20
+ - Apache
21
+ set-cookie:
22
+ - ci_session=a%3A5%3A%7Bs%3A10%3A%22session_id%22%3Bs%3A32%3A%225ee5f19c568590f29ec547cf0cbb15fc%22%3Bs%3A10%3A%22ip_address%22%3Bs%3A14%3A%22198.48.204.118%22%3Bs%3A10%3A%22user_agent%22%3Bs%3A14%3A%22Faraday+v0.9.1%22%3Bs%3A13%3A%22last_activity%22%3Bi%3A1452477010%3Bs%3A9%3A%22user_data%22%3Bs%3A0%3A%22%22%3B%7Da4e6d71e7310fa2b434a1efda6aa9267;
23
+ expires=Mon, 11-Jan-2016 03:50:10 GMT; Max-Age=7200; path=/
24
+ vary:
25
+ - Accept-Encoding
26
+ content-length:
27
+ - '62'
28
+ connection:
29
+ - close
30
+ content-type:
31
+ - text/html
32
+ body:
33
+ encoding: ASCII-8BIT
34
+ string: '{"error":"missing key and or search term"}'
35
+ http_version:
36
+ recorded_at: Mon, 11 Jan 2016 01:50:11 GMT
37
+ recorded_with: VCR 3.0.1
@@ -11,9 +11,9 @@ module WhosGotDirt
11
11
  end
12
12
 
13
13
  @template = {
14
- '@type' => 'Person',
15
- 'id' => 123,
14
+ '@type' => 'Entity',
16
15
  'name' => '/fn',
16
+ 'birth_date' => 2015,
17
17
  'identifiers' => [{
18
18
  'identifier' => '/id',
19
19
  'scheme' => 'ACME',
@@ -26,16 +26,20 @@ module WhosGotDirt
26
26
 
27
27
  def to_a
28
28
  parsed_body.map do |data|
29
- Result.new('Person', renderer.result(data), self).finalize!
29
+ Result.new('Entity', renderer.result(data), self).finalize!
30
30
  end
31
31
  end
32
32
  end
33
33
  end
34
34
 
35
+ let :body do
36
+ '[{"fn":"John Smith","id":"john-smith"},{"fn":"John Aaron Smith","id":"john-aaron-smith"}]'
37
+ end
38
+
35
39
  let :response do
36
40
  env = Faraday::Env.new
37
41
  env.url = 'https://api.example.com/endpoint?name~=John+Smith'
38
- env.body = '[{"fn":"John Smith","id":"john-smith"},{"fn":"John Aaron Smith","id":"john-aaron-smith"}]'
42
+ env.body = body
39
43
  Faraday::Response.new(env)
40
44
  end
41
45
 
@@ -45,9 +49,9 @@ module WhosGotDirt
45
49
 
46
50
  let :template do
47
51
  {
48
- '@type' => 'Person',
49
- 'id' => 123,
52
+ '@type' => 'Entity',
50
53
  'name' => '/fn',
54
+ 'birth_date' => 2015,
51
55
  'identifiers' => [{
52
56
  'identifier' => '/id',
53
57
  'scheme' => 'ACME',
@@ -89,9 +93,9 @@ module WhosGotDirt
89
93
  describe '#to_a' do
90
94
  it 'should return the results' do
91
95
  expect(instance.to_a).to eq([{
92
- '@type' => 'Person',
93
- 'id' => '123',
96
+ '@type' => 'Entity',
94
97
  'name' => 'John Smith',
98
+ 'birth_date' => '2015',
95
99
  'identifiers' => [{
96
100
  'identifier' => 'john-smith',
97
101
  'scheme' => 'ACME',
@@ -101,9 +105,9 @@ module WhosGotDirt
101
105
  'note' => 'MyResponse',
102
106
  }],
103
107
  }, {
104
- '@type' => 'Person',
105
- 'id' => '123',
108
+ '@type' => 'Entity',
106
109
  'name' => 'John Aaron Smith',
110
+ 'birth_date' => '2015',
107
111
  'identifiers' => [{
108
112
  'identifier' => 'john-aaron-smith',
109
113
  'scheme' => 'ACME',
@@ -115,5 +119,11 @@ module WhosGotDirt
115
119
  }])
116
120
  end
117
121
  end
122
+
123
+ describe '#error_message' do
124
+ it 'should return the parsed response body' do
125
+ expect(instance.error_message).to eq(body)
126
+ end
127
+ end
118
128
  end
119
129
  end
@@ -1,30 +1,48 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
2
 
3
3
  module WhosGotDirt::Responses::Entity
4
- RSpec.describe LittleSis, vcr: {cassette_name: 'little_sis_entity'} do
5
- let :response do
6
- Faraday.get("https://api.littlesis.org/entities.xml?q=bar&_key=#{ENV['LITTLE_SIS_API_KEY']}")
7
- end
4
+ RSpec.describe LittleSis do
5
+ context 'when successful', vcr: {cassette_name: 'little_sis_entity'} do
6
+ let :response do
7
+ Faraday.get("https://api.littlesis.org/entities.xml?q=bar&_key=#{ENV['LITTLE_SIS_API_KEY']}")
8
+ end
8
9
 
9
- let :instance do
10
- LittleSis.new(response)
11
- end
10
+ let :instance do
11
+ LittleSis.new(response)
12
+ end
12
13
 
13
- describe '#to_a' do
14
- it 'should return the results' do
15
- expect{instance.to_a}.to_not raise_error
14
+ describe '#to_a' do
15
+ it 'should return the results' do
16
+ expect{instance.to_a}.to_not raise_error
17
+ end
16
18
  end
17
- end
18
19
 
19
- describe '#count' do
20
- it 'should return the number of results' do
21
- expect(instance.count).to be > 1_000
20
+ describe '#count' do
21
+ it 'should return the number of results' do
22
+ expect(instance.count).to be > 1_000
23
+ end
24
+ end
25
+
26
+ describe '#page' do
27
+ it 'should return the current page number' do
28
+ expect(instance.page).to eq(1)
29
+ end
22
30
  end
23
31
  end
24
32
 
25
- describe '#page' do
26
- it 'should return the current page number' do
27
- expect(instance.page).to eq(1)
33
+ context 'when unsuccessful', vcr: {cassette_name: 'little_sis_entity_error'} do
34
+ let :response do
35
+ Faraday.get("https://api.littlesis.org/entities.xml?q=bar")
36
+ end
37
+
38
+ let :instance do
39
+ LittleSis.new(response)
40
+ end
41
+
42
+ describe '#error_message' do
43
+ it 'should return the error message' do
44
+ expect(instance.error_message).to eq('Your request must include a query parameter named "_key" with a valid API key value. To obtain an API key, visit http://api.littlesis.org/register.')
45
+ end
28
46
  end
29
47
  end
30
48
  end
@@ -1,24 +1,42 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
2
 
3
3
  module WhosGotDirt::Responses::Entity
4
- RSpec.describe OpenDuka, vcr: {cassette_name: 'open_duka_entity'} do
5
- let :response do
6
- Faraday.get("http://www.openduka.org/index.php/api/search?term=the&key=#{ENV['OPEN_DUKA_API_KEY']}")
7
- end
4
+ RSpec.describe OpenDuka do
5
+ context 'when successful', vcr: {cassette_name: 'open_duka_entity'} do
6
+ let :response do
7
+ Faraday.get("http://www.openduka.org/index.php/api/search?term=the&key=#{ENV['OPEN_DUKA_API_KEY']}")
8
+ end
8
9
 
9
- let :instance do
10
- OpenDuka.new(response)
11
- end
10
+ let :instance do
11
+ OpenDuka.new(response)
12
+ end
13
+
14
+ describe '#to_a' do
15
+ it 'should return the results' do
16
+ expect{instance.to_a}.to_not raise_error
17
+ end
18
+ end
12
19
 
13
- describe '#to_a' do
14
- it 'should return the results' do
15
- expect{instance.to_a}.to_not raise_error
20
+ describe '#count' do
21
+ it 'should return the number of results' do
22
+ expect(instance.count).to be > 1_000
23
+ end
16
24
  end
17
25
  end
18
26
 
19
- describe '#count' do
20
- it 'should return the number of results' do
21
- expect(instance.count).to be > 1_000
27
+ context 'when unsuccessful', vcr: {cassette_name: 'open_duka_entity_error'} do
28
+ let :response do
29
+ Faraday.get("http://www.openduka.org/index.php/api/search?term=the")
30
+ end
31
+
32
+ let :instance do
33
+ OpenDuka.new(response)
34
+ end
35
+
36
+ describe '#error_message' do
37
+ it 'should return the error message' do
38
+ expect(instance.error_message).to eq('missing key and or search term')
39
+ end
22
40
  end
23
41
  end
24
42
  end
@@ -1,30 +1,48 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
2
 
3
3
  module WhosGotDirt::Responses::List
4
- RSpec.describe LittleSis, vcr: {cassette_name: 'little_sis_list'} do
5
- let :response do
6
- Faraday.get("https://api.littlesis.org/lists.xml?q=united&_key=#{ENV['LITTLE_SIS_API_KEY']}")
7
- end
4
+ RSpec.describe LittleSis do
5
+ context 'when successful', vcr: {cassette_name: 'little_sis_list'} do
6
+ let :response do
7
+ Faraday.get("https://api.littlesis.org/lists.xml?q=united&_key=#{ENV['LITTLE_SIS_API_KEY']}")
8
+ end
8
9
 
9
- let :instance do
10
- LittleSis.new(response)
11
- end
10
+ let :instance do
11
+ LittleSis.new(response)
12
+ end
12
13
 
13
- describe '#to_a' do
14
- it 'should return the results' do
15
- expect{instance.to_a}.to_not raise_error
14
+ describe '#to_a' do
15
+ it 'should return the results' do
16
+ expect{instance.to_a}.to_not raise_error
17
+ end
16
18
  end
17
- end
18
19
 
19
- describe '#count' do
20
- it 'should return the number of results' do
21
- expect(instance.count).to be > 10
20
+ describe '#count' do
21
+ it 'should return the number of results' do
22
+ expect(instance.count).to be > 10
23
+ end
24
+ end
25
+
26
+ describe '#page' do
27
+ it 'should return the current page number' do
28
+ expect(instance.page).to eq(1)
29
+ end
22
30
  end
23
31
  end
24
32
 
25
- describe '#page' do
26
- it 'should return the current page number' do
27
- expect(instance.page).to eq(1)
33
+ context 'when unsuccessful', vcr: {cassette_name: 'little_sis_list_error'} do
34
+ let :response do
35
+ Faraday.get("https://api.littlesis.org/lists.xml?q=united")
36
+ end
37
+
38
+ let :instance do
39
+ LittleSis.new(response)
40
+ end
41
+
42
+ describe '#error_message' do
43
+ it 'should return the error message' do
44
+ expect(instance.error_message).to eq('Your request must include a query parameter named "_key" with a valid API key value. To obtain an API key, visit http://api.littlesis.org/register.')
45
+ end
28
46
  end
29
47
  end
30
48
  end
data/spec/result_spec.rb CHANGED
@@ -4,8 +4,8 @@ module WhosGotDirt
4
4
  RSpec.describe Result do
5
5
  let :result do
6
6
  {
7
- 'id' => 123,
8
7
  'name' => 'John Smith',
8
+ 'birth_date' => 2015,
9
9
  'identifiers' => [{
10
10
  'scheme' => 'ACME',
11
11
  }, {
@@ -24,12 +24,12 @@ module WhosGotDirt
24
24
  end
25
25
 
26
26
  let :instance do
27
- Result.new('Person', result, response)
27
+ Result.new('Entity', result, response)
28
28
  end
29
29
 
30
30
  describe '#initialize' do
31
31
  it 'should set the type, result and response' do
32
- expect(instance.type).to eq('Person')
32
+ expect(instance.type).to eq('Entity')
33
33
  expect(instance.result).to eq(result)
34
34
  expect(instance.response).to eq(response)
35
35
  end
@@ -38,8 +38,8 @@ module WhosGotDirt
38
38
  describe '#add_source!' do
39
39
  it 'should add a source to a result' do
40
40
  expect(instance.add_source!).to eq({
41
- 'id' => 123,
42
41
  'name' => 'John Smith',
42
+ 'birth_date' => 2015,
43
43
  'identifiers' => [{
44
44
  'scheme' => 'ACME',
45
45
  }, {
@@ -58,8 +58,8 @@ module WhosGotDirt
58
58
  describe 'validate!' do
59
59
  it 'should validate the result' do
60
60
  expect(instance.validate!).to eq({
61
- 'id' => '123',
62
61
  'name' => 'John Smith',
62
+ 'birth_date' => '2015',
63
63
  'identifiers' => [{
64
64
  'identifier' => 'john-smith',
65
65
  }],
@@ -74,8 +74,8 @@ module WhosGotDirt
74
74
  describe '#finalize!' do
75
75
  it 'should finalize the result' do
76
76
  expect(instance.finalize!).to eq({
77
- 'id' => '123',
78
77
  'name' => 'John Smith',
78
+ 'birth_date' => '2015',
79
79
  'identifiers' => [{
80
80
  'identifier' => 'john-smith',
81
81
  }],