mailroute 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mailroute (0.0.3)
4
+ mailroute (0.0.4)
5
5
  activeresource
6
6
  json_pure
7
7
  rest-client
@@ -17,5 +17,44 @@ module Mailroute
17
17
  prefix_options, query_options = split_options(prefix_options) if query_options.nil?
18
18
  "#{prefix(prefix_options)}admins/#{scope[:name]}/#{scope[:id]}/admin/#{URI.parser.escape id.to_s}/#{query_string(query_options)}"
19
19
  end
20
+
21
+ def element_path
22
+ super(scope)
23
+ end
24
+
25
+ def regenerate_api_key
26
+ response = connection.post(element_path + 'regenerate_api_key/', nil, self.class.headers)
27
+ self.class.format.decode(response.body)['api_key']
28
+ end
29
+
30
+ def scope
31
+ raise 'invalid state' unless resource_uri =~ /admins\/([^\/]+)\/(\d+)\/admin/
32
+ { :scope => { :id => $2.to_i, :name => $1 } }
33
+ end
34
+
35
+ def customer
36
+ if resource_uri =~ /admins\/customer\/(\d+)\/admin/
37
+ @customer ||= Mailroute::Customer.get($1.to_i)
38
+ else
39
+ nil
40
+ end
41
+ end
42
+
43
+ def reseller
44
+ if resource_uri =~ /admins\/reseller\/(\d+)\/admin/
45
+ @reseller ||= Mailroute::Reseller.get($1.to_i)
46
+ else
47
+ nil
48
+ end
49
+ end
50
+
51
+ def reload
52
+ @customer = @reseller = nil
53
+ super
54
+ end
55
+
56
+ def self.get(id, scope)
57
+ find(id, :params => { :scope => { :name => scope.keys.first, :id => scope.values.first } })
58
+ end
20
59
  end
21
60
  end
@@ -1,3 +1,3 @@
1
1
  module Mailroute
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -10,4 +10,32 @@ describe Mailroute::Admin, :vcr => true do
10
10
  admins.count.should == 3
11
11
  end
12
12
  end
13
- end
13
+
14
+ describe '#get' do
15
+ context 'getting customer admin' do
16
+ subject(:admin) { Mailroute::Admin.get(9252, :customer => 11372) }
17
+
18
+ its(:id) { should == 9252 }
19
+ its(:email) { should == 'admin@example.com' }
20
+ its(:customer) { should be_a Mailroute::Customer }
21
+ end
22
+ end
23
+
24
+ describe '#regenerate_api_key' do
25
+ context 'an admin' do
26
+ let(:admin) { Mailroute::Admin.get(9252, :customer => 11372) }
27
+
28
+ context 'regenerating api key' do
29
+ subject(:new_key) { admin.regenerate_api_key }
30
+
31
+ it { should match /\A[0-9a-f]{40}\Z/ }
32
+
33
+ context 'regenerating api key once again' do
34
+ let(:another_key) { admin.regenerate_api_key }
35
+
36
+ it { should_not == another_key }
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,71 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://admin-dev.mailroute.net/api/v1/admins/customer/11372/admin/9252/
6
+ body:
7
+ string: ""
8
+ headers:
9
+ Accept:
10
+ - application/json
11
+ Authorization:
12
+ - ApiKey test_ruby:93ec480a01deb532ffb592ba711013e14422c4f1
13
+ response:
14
+ status:
15
+ code: 200
16
+ message: OK
17
+ headers:
18
+ Vary:
19
+ - Accept, Cookie
20
+ - Accept-Encoding
21
+ Content-Type:
22
+ - application/json; charset=utf-8
23
+ Server:
24
+ - nginx/1.2.6
25
+ Cache-Control:
26
+ - no-cache
27
+ Transfer-Encoding:
28
+ - chunked
29
+ Date:
30
+ - Thu, 02 May 2013 20:55:53 GMT
31
+ Connection:
32
+ - keep-alive
33
+ body:
34
+ string: "{\"customer\": null, \"date_joined\": \"Wed, 1 May 2013 12:03:04 -0700\", \"email\": \"admin@example.com\", \"id\": 9252, \"is_active\": true, \"last_login\": \"Wed, 1 May 2013 12:03:04 -0700\", \"reseller\": null, \"resource_uri\": \"/api/v1/admins/customer/11372/admin/9252/\", \"send_welcome\": null, \"username\": \"admin@example.com\"}"
35
+ http_version:
36
+ recorded_at: Thu, 02 May 2013 20:55:55 GMT
37
+ - request:
38
+ method: get
39
+ uri: https://admin-dev.mailroute.net/api/v1/customer/11372/
40
+ body:
41
+ string: ""
42
+ headers:
43
+ Accept:
44
+ - application/json
45
+ Authorization:
46
+ - ApiKey test_ruby:93ec480a01deb532ffb592ba711013e14422c4f1
47
+ response:
48
+ status:
49
+ code: 200
50
+ message: OK
51
+ headers:
52
+ Vary:
53
+ - Accept, Cookie
54
+ - Accept-Encoding
55
+ Content-Type:
56
+ - application/json; charset=utf-8
57
+ Server:
58
+ - nginx/1.2.6
59
+ Cache-Control:
60
+ - no-cache
61
+ Transfer-Encoding:
62
+ - chunked
63
+ Date:
64
+ - Thu, 02 May 2013 20:55:55 GMT
65
+ Connection:
66
+ - keep-alive
67
+ body:
68
+ string: "{\"absolute_url\": \"/customer/11372/\", \"allow_branding\": false, \"branding_info\": \"/api/v1/brandinginfo/30483/\", \"created_at\": \"Mon, 29 Apr 2013 05:19:28 -0700\", \"id\": 11372, \"is_full_user_list\": false, \"name\": \"foreign_customerreseller2969b7d5072d33933060979ef14fb4b3\", \"reported_user_count\": null, \"reseller\": \"/api/v1/reseller/19552/\", \"resource_uri\": \"/api/v1/customer/11372/\", \"updated_at\": \"Mon, 29 Apr 2013 05:19:29 -0700\"}"
69
+ http_version:
70
+ recorded_at: Thu, 02 May 2013 20:55:57 GMT
71
+ recorded_with: VCR 2.4.0
@@ -0,0 +1,37 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://admin-dev.mailroute.net/api/v1/admins/customer/11372/admin/9252/
6
+ body:
7
+ string: ""
8
+ headers:
9
+ Accept:
10
+ - application/json
11
+ Authorization:
12
+ - ApiKey test_ruby:93ec480a01deb532ffb592ba711013e14422c4f1
13
+ response:
14
+ status:
15
+ code: 200
16
+ message: OK
17
+ headers:
18
+ Vary:
19
+ - Accept, Cookie
20
+ - Accept-Encoding
21
+ Content-Type:
22
+ - application/json; charset=utf-8
23
+ Server:
24
+ - nginx/1.2.6
25
+ Cache-Control:
26
+ - no-cache
27
+ Transfer-Encoding:
28
+ - chunked
29
+ Date:
30
+ - Thu, 02 May 2013 20:55:52 GMT
31
+ Connection:
32
+ - keep-alive
33
+ body:
34
+ string: "{\"customer\": null, \"date_joined\": \"Wed, 1 May 2013 12:03:04 -0700\", \"email\": \"admin@example.com\", \"id\": 9252, \"is_active\": true, \"last_login\": \"Wed, 1 May 2013 12:03:04 -0700\", \"reseller\": null, \"resource_uri\": \"/api/v1/admins/customer/11372/admin/9252/\", \"send_welcome\": null, \"username\": \"admin@example.com\"}"
35
+ http_version:
36
+ recorded_at: Thu, 02 May 2013 20:55:54 GMT
37
+ recorded_with: VCR 2.4.0
@@ -0,0 +1,37 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://admin-dev.mailroute.net/api/v1/admins/customer/11372/admin/9252/
6
+ body:
7
+ string: ""
8
+ headers:
9
+ Accept:
10
+ - application/json
11
+ Authorization:
12
+ - ApiKey test_ruby:93ec480a01deb532ffb592ba711013e14422c4f1
13
+ response:
14
+ status:
15
+ code: 200
16
+ message: OK
17
+ headers:
18
+ Vary:
19
+ - Accept, Cookie
20
+ - Accept-Encoding
21
+ Content-Type:
22
+ - application/json; charset=utf-8
23
+ Server:
24
+ - nginx/1.2.6
25
+ Cache-Control:
26
+ - no-cache
27
+ Transfer-Encoding:
28
+ - chunked
29
+ Date:
30
+ - Thu, 02 May 2013 20:55:51 GMT
31
+ Connection:
32
+ - keep-alive
33
+ body:
34
+ string: "{\"customer\": null, \"date_joined\": \"Wed, 1 May 2013 12:03:04 -0700\", \"email\": \"admin@example.com\", \"id\": 9252, \"is_active\": true, \"last_login\": \"Wed, 1 May 2013 12:03:04 -0700\", \"reseller\": null, \"resource_uri\": \"/api/v1/admins/customer/11372/admin/9252/\", \"send_welcome\": null, \"username\": \"admin@example.com\"}"
35
+ http_version:
36
+ recorded_at: Thu, 02 May 2013 20:55:53 GMT
37
+ recorded_with: VCR 2.4.0
@@ -0,0 +1,70 @@
1
+ ---
2
+ recorded_with: VCR 2.4.0
3
+ http_interactions:
4
+ - request:
5
+ method: get
6
+ uri: https://admin-dev.mailroute.net/api/v1/admins/customer/11372/admin/9252/
7
+ body:
8
+ string: ""
9
+ headers:
10
+ Authorization:
11
+ - ApiKey test_ruby:93ec480a01deb532ffb592ba711013e14422c4f1
12
+ Accept:
13
+ - application/json
14
+ response:
15
+ status:
16
+ code: 200
17
+ message: OK
18
+ headers:
19
+ Server:
20
+ - nginx/1.2.6
21
+ Connection:
22
+ - keep-alive
23
+ Cache-Control:
24
+ - no-cache
25
+ Date:
26
+ - Thu, 02 May 2013 21:01:55 GMT
27
+ Transfer-Encoding:
28
+ - chunked
29
+ Content-Type:
30
+ - application/json; charset=utf-8
31
+ Vary:
32
+ - Accept, Cookie
33
+ - Accept-Encoding
34
+ body:
35
+ string: "{\"customer\": null, \"date_joined\": \"Wed, 1 May 2013 12:03:04 -0700\", \"email\": \"admin@example.com\", \"id\": 9252, \"is_active\": true, \"last_login\": \"Wed, 1 May 2013 12:03:04 -0700\", \"reseller\": null, \"resource_uri\": \"/api/v1/admins/customer/11372/admin/9252/\", \"send_welcome\": null, \"username\": \"admin@example.com\"}"
36
+ http_version:
37
+ recorded_at: Thu, 02 May 2013 21:01:57 GMT
38
+ - request:
39
+ method: post
40
+ uri: https://admin-dev.mailroute.net/api/v1/admins/customer/11372/admin/9252/regenerate_api_key/
41
+ body:
42
+ string: ""
43
+ headers:
44
+ Authorization:
45
+ - ApiKey test_ruby:93ec480a01deb532ffb592ba711013e14422c4f1
46
+ Content-Type:
47
+ - application/json
48
+ Accept:
49
+ - "*/*"
50
+ response:
51
+ status:
52
+ code: 202
53
+ message: ACCEPTED
54
+ headers:
55
+ Server:
56
+ - nginx/1.2.6
57
+ Connection:
58
+ - keep-alive
59
+ Date:
60
+ - Thu, 02 May 2013 21:01:57 GMT
61
+ Transfer-Encoding:
62
+ - chunked
63
+ Content-Type:
64
+ - application/json
65
+ Vary:
66
+ - Accept, Cookie
67
+ body:
68
+ string: "{\"api_key\": \"f524aa71c3976423fb905fe5e6afe1ef72292931\"}"
69
+ http_version:
70
+ recorded_at: Thu, 02 May 2013 21:01:59 GMT
@@ -0,0 +1,103 @@
1
+ ---
2
+ recorded_with: VCR 2.4.0
3
+ http_interactions:
4
+ - request:
5
+ method: get
6
+ uri: https://admin-dev.mailroute.net/api/v1/admins/customer/11372/admin/9252/
7
+ body:
8
+ string: ""
9
+ headers:
10
+ Authorization:
11
+ - ApiKey test_ruby:93ec480a01deb532ffb592ba711013e14422c4f1
12
+ Accept:
13
+ - application/json
14
+ response:
15
+ status:
16
+ code: 200
17
+ message: OK
18
+ headers:
19
+ Server:
20
+ - nginx/1.2.6
21
+ Connection:
22
+ - keep-alive
23
+ Cache-Control:
24
+ - no-cache
25
+ Date:
26
+ - Thu, 02 May 2013 21:01:59 GMT
27
+ Transfer-Encoding:
28
+ - chunked
29
+ Content-Type:
30
+ - application/json; charset=utf-8
31
+ Vary:
32
+ - Accept, Cookie
33
+ - Accept-Encoding
34
+ body:
35
+ string: "{\"customer\": null, \"date_joined\": \"Wed, 1 May 2013 12:03:04 -0700\", \"email\": \"admin@example.com\", \"id\": 9252, \"is_active\": true, \"last_login\": \"Wed, 1 May 2013 12:03:04 -0700\", \"reseller\": null, \"resource_uri\": \"/api/v1/admins/customer/11372/admin/9252/\", \"send_welcome\": null, \"username\": \"admin@example.com\"}"
36
+ http_version:
37
+ recorded_at: Thu, 02 May 2013 21:02:01 GMT
38
+ - request:
39
+ method: post
40
+ uri: https://admin-dev.mailroute.net/api/v1/admins/customer/11372/admin/9252/regenerate_api_key/
41
+ body:
42
+ string: ""
43
+ headers:
44
+ Authorization:
45
+ - ApiKey test_ruby:93ec480a01deb532ffb592ba711013e14422c4f1
46
+ Content-Type:
47
+ - application/json
48
+ Accept:
49
+ - "*/*"
50
+ response:
51
+ status:
52
+ code: 202
53
+ message: ACCEPTED
54
+ headers:
55
+ Server:
56
+ - nginx/1.2.6
57
+ Connection:
58
+ - keep-alive
59
+ Date:
60
+ - Thu, 02 May 2013 21:02:00 GMT
61
+ Transfer-Encoding:
62
+ - chunked
63
+ Content-Type:
64
+ - application/json
65
+ Vary:
66
+ - Accept, Cookie
67
+ body:
68
+ string: "{\"api_key\": \"4b265ac06932bebc224a38df84c076b3cf388a55\"}"
69
+ http_version:
70
+ recorded_at: Thu, 02 May 2013 21:02:02 GMT
71
+ - request:
72
+ method: post
73
+ uri: https://admin-dev.mailroute.net/api/v1/admins/customer/11372/admin/9252/regenerate_api_key/
74
+ body:
75
+ string: ""
76
+ headers:
77
+ Authorization:
78
+ - ApiKey test_ruby:93ec480a01deb532ffb592ba711013e14422c4f1
79
+ Content-Type:
80
+ - application/json
81
+ Accept:
82
+ - "*/*"
83
+ response:
84
+ status:
85
+ code: 202
86
+ message: ACCEPTED
87
+ headers:
88
+ Server:
89
+ - nginx/1.2.6
90
+ Connection:
91
+ - keep-alive
92
+ Date:
93
+ - Thu, 02 May 2013 21:02:01 GMT
94
+ Transfer-Encoding:
95
+ - chunked
96
+ Content-Type:
97
+ - application/json
98
+ Vary:
99
+ - Accept, Cookie
100
+ body:
101
+ string: "{\"api_key\": \"cb5ea4d686d749804f29583a204c0ff1736c24cd\"}"
102
+ http_version:
103
+ recorded_at: Thu, 02 May 2013 21:02:03 GMT
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailroute
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Viktar Basharymau
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-05-01 00:00:00 Z
18
+ date: 2013-05-02 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rest-client
@@ -246,6 +246,11 @@ files:
246
246
  - spec/support/mailroute_configuration_helper.rb
247
247
  - spec/vcr_cassettes/Mailroute/_check_connection/when_configured_with_correct_credentials/should_return_true.yml
248
248
  - spec/vcr_cassettes/Mailroute/_check_connection/when_configured_with_incorrect_credentials/should_raise_Unauthorized_error.yml
249
+ - spec/vcr_cassettes/Mailroute_Admin/_get/getting_customer_admin/customer/.yml
250
+ - spec/vcr_cassettes/Mailroute_Admin/_get/getting_customer_admin/email/.yml
251
+ - spec/vcr_cassettes/Mailroute_Admin/_get/getting_customer_admin/id/.yml
252
+ - spec/vcr_cassettes/Mailroute_Admin/_regenerate_api_key/an_admin/regenerating_api_key/.yml
253
+ - spec/vcr_cassettes/Mailroute_Admin/_regenerate_api_key/an_admin/regenerating_api_key/regenerating_api_key_once_again/.yml
249
254
  - spec/vcr_cassettes/Mailroute_Admin/basic_operations/should_perform_basic_read_operations.yml
250
255
  - spec/vcr_cassettes/Mailroute_Customer/_admins/should_return_a_list_of_its_admins.yml
251
256
  - spec/vcr_cassettes/Mailroute_Customer/_branding_info/should_return_its_branding_info.yml
@@ -433,6 +438,11 @@ test_files:
433
438
  - spec/support/mailroute_configuration_helper.rb
434
439
  - spec/vcr_cassettes/Mailroute/_check_connection/when_configured_with_correct_credentials/should_return_true.yml
435
440
  - spec/vcr_cassettes/Mailroute/_check_connection/when_configured_with_incorrect_credentials/should_raise_Unauthorized_error.yml
441
+ - spec/vcr_cassettes/Mailroute_Admin/_get/getting_customer_admin/customer/.yml
442
+ - spec/vcr_cassettes/Mailroute_Admin/_get/getting_customer_admin/email/.yml
443
+ - spec/vcr_cassettes/Mailroute_Admin/_get/getting_customer_admin/id/.yml
444
+ - spec/vcr_cassettes/Mailroute_Admin/_regenerate_api_key/an_admin/regenerating_api_key/.yml
445
+ - spec/vcr_cassettes/Mailroute_Admin/_regenerate_api_key/an_admin/regenerating_api_key/regenerating_api_key_once_again/.yml
436
446
  - spec/vcr_cassettes/Mailroute_Admin/basic_operations/should_perform_basic_read_operations.yml
437
447
  - spec/vcr_cassettes/Mailroute_Customer/_admins/should_return_a_list_of_its_admins.yml
438
448
  - spec/vcr_cassettes/Mailroute_Customer/_branding_info/should_return_its_branding_info.yml