gocardless-pro 0.1.0

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.
Files changed (91) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +2 -0
  3. data/Gemfile +2 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +132 -0
  6. data/circle.yml +18 -0
  7. data/demo.rb +10 -0
  8. data/gocardless-pro.gemspec +27 -0
  9. data/lib/gocardless-pro.rb +243 -0
  10. data/lib/gocardless-pro/api_service.rb +57 -0
  11. data/lib/gocardless-pro/error.rb +42 -0
  12. data/lib/gocardless-pro/error/gocardless_error.rb +5 -0
  13. data/lib/gocardless-pro/error/invalid_api_usage_error.rb +5 -0
  14. data/lib/gocardless-pro/error/invalid_state_error.rb +5 -0
  15. data/lib/gocardless-pro/error/validation_error.rb +5 -0
  16. data/lib/gocardless-pro/list_response.rb +34 -0
  17. data/lib/gocardless-pro/paginator.rb +37 -0
  18. data/lib/gocardless-pro/request.rb +69 -0
  19. data/lib/gocardless-pro/resources/api_key.rb +62 -0
  20. data/lib/gocardless-pro/resources/creditor.rb +83 -0
  21. data/lib/gocardless-pro/resources/creditor_bank_account.rb +78 -0
  22. data/lib/gocardless-pro/resources/customer.rb +72 -0
  23. data/lib/gocardless-pro/resources/customer_bank_account.rb +80 -0
  24. data/lib/gocardless-pro/resources/event.rb +75 -0
  25. data/lib/gocardless-pro/resources/helper.rb +29 -0
  26. data/lib/gocardless-pro/resources/mandate.rb +70 -0
  27. data/lib/gocardless-pro/resources/payment.rb +86 -0
  28. data/lib/gocardless-pro/resources/payout.rb +66 -0
  29. data/lib/gocardless-pro/resources/publishable_api_key.rb +51 -0
  30. data/lib/gocardless-pro/resources/redirect_flow.rb +104 -0
  31. data/lib/gocardless-pro/resources/refund.rb +70 -0
  32. data/lib/gocardless-pro/resources/role.rb +101 -0
  33. data/lib/gocardless-pro/resources/subscription.rb +152 -0
  34. data/lib/gocardless-pro/resources/user.rb +60 -0
  35. data/lib/gocardless-pro/response.rb +77 -0
  36. data/lib/gocardless-pro/services/api_key_service.rb +130 -0
  37. data/lib/gocardless-pro/services/base_service.rb +29 -0
  38. data/lib/gocardless-pro/services/creditor_bank_account_service.rb +122 -0
  39. data/lib/gocardless-pro/services/creditor_service.rb +112 -0
  40. data/lib/gocardless-pro/services/customer_bank_account_service.rb +153 -0
  41. data/lib/gocardless-pro/services/customer_service.rb +112 -0
  42. data/lib/gocardless-pro/services/event_service.rb +80 -0
  43. data/lib/gocardless-pro/services/helper_service.rb +97 -0
  44. data/lib/gocardless-pro/services/mandate_service.rb +170 -0
  45. data/lib/gocardless-pro/services/payment_service.rb +164 -0
  46. data/lib/gocardless-pro/services/payout_service.rb +80 -0
  47. data/lib/gocardless-pro/services/publishable_api_key_service.rb +130 -0
  48. data/lib/gocardless-pro/services/redirect_flow_service.rb +96 -0
  49. data/lib/gocardless-pro/services/refund_service.rb +126 -0
  50. data/lib/gocardless-pro/services/role_service.rb +127 -0
  51. data/lib/gocardless-pro/services/subscription_service.rb +133 -0
  52. data/lib/gocardless-pro/services/user_service.rb +148 -0
  53. data/lib/gocardless-pro/version.rb +8 -0
  54. data/spec/api_service_spec.rb +69 -0
  55. data/spec/client_spec.rb +29 -0
  56. data/spec/error_spec.rb +44 -0
  57. data/spec/resources/api_key_spec.rb +85 -0
  58. data/spec/resources/creditor_bank_account_spec.rb +109 -0
  59. data/spec/resources/creditor_spec.rb +125 -0
  60. data/spec/resources/customer_bank_account_spec.rb +109 -0
  61. data/spec/resources/customer_spec.rb +127 -0
  62. data/spec/resources/event_spec.rb +113 -0
  63. data/spec/resources/helper_spec.rb +23 -0
  64. data/spec/resources/mandate_spec.rb +97 -0
  65. data/spec/resources/payment_spec.rb +129 -0
  66. data/spec/resources/payout_spec.rb +89 -0
  67. data/spec/resources/publishable_api_key_spec.rb +63 -0
  68. data/spec/resources/redirect_flow_spec.rb +97 -0
  69. data/spec/resources/refund_spec.rb +77 -0
  70. data/spec/resources/role_spec.rb +63 -0
  71. data/spec/resources/subscription_spec.rb +157 -0
  72. data/spec/resources/user_spec.rb +85 -0
  73. data/spec/response_spec.rb +79 -0
  74. data/spec/services/api_key_service_spec.rb +362 -0
  75. data/spec/services/creditor_bank_account_service_spec.rb +365 -0
  76. data/spec/services/creditor_service_spec.rb +339 -0
  77. data/spec/services/customer_bank_account_service_spec.rb +404 -0
  78. data/spec/services/customer_service_spec.rb +365 -0
  79. data/spec/services/event_service_spec.rb +172 -0
  80. data/spec/services/helper_service_spec.rb +123 -0
  81. data/spec/services/mandate_service_spec.rb +449 -0
  82. data/spec/services/payment_service_spec.rb +497 -0
  83. data/spec/services/payout_service_spec.rb +172 -0
  84. data/spec/services/publishable_api_key_service_spec.rb +336 -0
  85. data/spec/services/redirect_flow_service_spec.rb +208 -0
  86. data/spec/services/refund_service_spec.rb +279 -0
  87. data/spec/services/role_service_spec.rb +336 -0
  88. data/spec/services/subscription_service_spec.rb +488 -0
  89. data/spec/services/user_service_spec.rb +433 -0
  90. data/spec/spec_helper.rb +91 -0
  91. metadata +255 -0
@@ -0,0 +1,126 @@
1
+ require_relative './base_service'
2
+
3
+ # encoding: utf-8
4
+ #
5
+ # WARNING: Do not edit by hand, this file was generated by Crank:
6
+ #
7
+ # https://github.com/gocardless/crank
8
+
9
+ module GoCardless
10
+ module Services
11
+ # Service for making requests to the Refund endpoints
12
+ class RefundService < BaseService
13
+ # Creates a new refund object.
14
+ #
15
+ # This fails with:<a
16
+ # name="refund_payment_invalid_state"></a><a
17
+ # name="total_amount_confirmation_invalid"></a>
18
+ #
19
+ # -
20
+ # `refund_payment_invalid_state` error if the linked
21
+ # [payment](https://developer.gocardless.com/pro/#api-endpoints-payments) isn't
22
+ # either `confirmed` or `paid_out`.
23
+ #
24
+ # - `total_amount_confirmation_invalid`
25
+ # if the confirmation amount doesn't match the total amount refunded for the
26
+ # payment. This safeguard is there to prevent two processes from creating
27
+ # refunds without awareness of each other.
28
+ #
29
+ # Example URL: /refunds
30
+ # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
31
+ # Else, they will be the body of the request.
32
+ def create(options = {}, custom_headers = {})
33
+ path = '/refunds'
34
+ new_options = {}
35
+ new_options[envelope_key] = options
36
+ options = new_options
37
+ response = make_request(:post, path, options, custom_headers)
38
+
39
+ Resources::Refund.new(unenvelope_body(response.body))
40
+ end
41
+
42
+ # Returns a
43
+ # [cursor-paginated](https://developer.gocardless.com/pro/#overview-cursor-pagination)
44
+ # list of your refunds.
45
+ # Example URL: /refunds
46
+ # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
47
+ # Else, they will be the body of the request.
48
+ def list(options = {}, custom_headers = {})
49
+ path = '/refunds'
50
+
51
+ response = make_request(:get, path, options, custom_headers)
52
+ ListResponse.new(
53
+ raw_response: response,
54
+ unenveloped_body: unenvelope_body(response.body),
55
+ resource_class: Resources::Refund
56
+ )
57
+ end
58
+
59
+ # Get a lazily enumerated list of all the items returned. This is simmilar to the `list` method but will paginate for you automatically.
60
+ #
61
+ # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
62
+ # Otherwise they will be the body of the request.
63
+ def all(options = {})
64
+ Paginator.new(
65
+ service: self,
66
+ path: '/refunds',
67
+ options: options
68
+ ).enumerator
69
+ end
70
+
71
+ # Retrieves all details for a single refund
72
+ # Example URL: /refunds/:identity
73
+ #
74
+ # @param identity # Unique identifier, beginning with "RF"
75
+ # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
76
+ # Else, they will be the body of the request.
77
+ def get(identity, options = {}, custom_headers = {})
78
+ path = sub_url('/refunds/:identity', 'identity' => identity)
79
+
80
+ response = make_request(:get, path, options, custom_headers)
81
+
82
+ Resources::Refund.new(unenvelope_body(response.body))
83
+ end
84
+
85
+ # Updates a refund object.
86
+ # Example URL: /refunds/:identity
87
+ #
88
+ # @param identity # Unique identifier, beginning with "RF"
89
+ # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
90
+ # Else, they will be the body of the request.
91
+ def update(identity, options = {}, custom_headers = {})
92
+ path = sub_url('/refunds/:identity', 'identity' => identity)
93
+
94
+ new_options = {}
95
+ new_options[envelope_key] = options
96
+ options = new_options
97
+ response = make_request(:put, path, options, custom_headers)
98
+
99
+ Resources::Refund.new(unenvelope_body(response.body))
100
+ end
101
+
102
+ # Unenvelope the response of the body using the service's `envelope_key`
103
+ #
104
+ # @param body [Hash]
105
+ def unenvelope_body(body)
106
+ body[envelope_key] || body['data']
107
+ end
108
+
109
+ private
110
+
111
+ # return the key which API responses will envelope data under
112
+ def envelope_key
113
+ 'refunds'
114
+ end
115
+
116
+ # take a URL with placeholder params and substitute them out for the acutal value
117
+ # @param url [String] the URL with placeholders in
118
+ # @param param_map [Hash] a hash of placeholders and their actual values
119
+ def sub_url(url, param_map)
120
+ param_map.reduce(url) do |new_url, (param, value)|
121
+ new_url.gsub(":#{param}", value)
122
+ end
123
+ end
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,127 @@
1
+ require_relative './base_service'
2
+
3
+ # encoding: utf-8
4
+ #
5
+ # WARNING: Do not edit by hand, this file was generated by Crank:
6
+ #
7
+ # https://github.com/gocardless/crank
8
+
9
+ module GoCardless
10
+ module Services
11
+ # Service for making requests to the Role endpoints
12
+ class RoleService < BaseService
13
+ # Create a role with set access permissions
14
+ # Example URL: /roles
15
+ # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
16
+ # Else, they will be the body of the request.
17
+ def create(options = {}, custom_headers = {})
18
+ path = '/roles'
19
+ new_options = {}
20
+ new_options[envelope_key] = options
21
+ options = new_options
22
+ response = make_request(:post, path, options, custom_headers)
23
+
24
+ Resources::Role.new(unenvelope_body(response.body))
25
+ end
26
+
27
+ # List all existing roles
28
+ # Example URL: /roles
29
+ # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
30
+ # Else, they will be the body of the request.
31
+ def list(options = {}, custom_headers = {})
32
+ path = '/roles'
33
+
34
+ response = make_request(:get, path, options, custom_headers)
35
+ ListResponse.new(
36
+ raw_response: response,
37
+ unenveloped_body: unenvelope_body(response.body),
38
+ resource_class: Resources::Role
39
+ )
40
+ end
41
+
42
+ # Get a lazily enumerated list of all the items returned. This is simmilar to the `list` method but will paginate for you automatically.
43
+ #
44
+ # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
45
+ # Otherwise they will be the body of the request.
46
+ def all(options = {})
47
+ Paginator.new(
48
+ service: self,
49
+ path: '/roles',
50
+ options: options
51
+ ).enumerator
52
+ end
53
+
54
+ # Retrieve all details for a single role
55
+ # Example URL: /roles/:identity
56
+ #
57
+ # @param identity # Unique identifier, beginning with "RO"
58
+ # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
59
+ # Else, they will be the body of the request.
60
+ def get(identity, options = {}, custom_headers = {})
61
+ path = sub_url('/roles/:identity', 'identity' => identity)
62
+
63
+ response = make_request(:get, path, options, custom_headers)
64
+
65
+ Resources::Role.new(unenvelope_body(response.body))
66
+ end
67
+
68
+ # Updates a role object. Supports all of the fields supported when creating a
69
+ # role.
70
+ # Example URL: /roles/:identity
71
+ #
72
+ # @param identity # Unique identifier, beginning with "RO"
73
+ # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
74
+ # Else, they will be the body of the request.
75
+ def update(identity, options = {}, custom_headers = {})
76
+ path = sub_url('/roles/:identity', 'identity' => identity)
77
+
78
+ new_options = {}
79
+ new_options[envelope_key] = options
80
+ options = new_options
81
+ response = make_request(:put, path, options, custom_headers)
82
+
83
+ Resources::Role.new(unenvelope_body(response.body))
84
+ end
85
+
86
+ # Disables a role
87
+ # Example URL: /roles/:identity/actions/disable
88
+ #
89
+ # @param identity # Unique identifier, beginning with "RO"
90
+ # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
91
+ # Else, they will be the body of the request.
92
+ def disable(identity, options = {}, custom_headers = {})
93
+ path = sub_url('/roles/:identity/actions/disable', 'identity' => identity)
94
+
95
+ new_options = {}
96
+ new_options['data'] = options
97
+ options = new_options
98
+ response = make_request(:post, path, options, custom_headers)
99
+
100
+ Resources::Role.new(unenvelope_body(response.body))
101
+ end
102
+
103
+ # Unenvelope the response of the body using the service's `envelope_key`
104
+ #
105
+ # @param body [Hash]
106
+ def unenvelope_body(body)
107
+ body[envelope_key] || body['data']
108
+ end
109
+
110
+ private
111
+
112
+ # return the key which API responses will envelope data under
113
+ def envelope_key
114
+ 'roles'
115
+ end
116
+
117
+ # take a URL with placeholder params and substitute them out for the acutal value
118
+ # @param url [String] the URL with placeholders in
119
+ # @param param_map [Hash] a hash of placeholders and their actual values
120
+ def sub_url(url, param_map)
121
+ param_map.reduce(url) do |new_url, (param, value)|
122
+ new_url.gsub(":#{param}", value)
123
+ end
124
+ end
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,133 @@
1
+ require_relative './base_service'
2
+
3
+ # encoding: utf-8
4
+ #
5
+ # WARNING: Do not edit by hand, this file was generated by Crank:
6
+ #
7
+ # https://github.com/gocardless/crank
8
+
9
+ module GoCardless
10
+ module Services
11
+ # Service for making requests to the Subscription endpoints
12
+ class SubscriptionService < BaseService
13
+ # Creates a new subscription object
14
+ # Example URL: /subscriptions
15
+ # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
16
+ # Else, they will be the body of the request.
17
+ def create(options = {}, custom_headers = {})
18
+ path = '/subscriptions'
19
+ new_options = {}
20
+ new_options[envelope_key] = options
21
+ options = new_options
22
+ response = make_request(:post, path, options, custom_headers)
23
+
24
+ Resources::Subscription.new(unenvelope_body(response.body))
25
+ end
26
+
27
+ # Returns a
28
+ # [cursor-paginated](https://developer.gocardless.com/pro/#overview-cursor-pagination)
29
+ # list of your subscriptions.
30
+ # Example URL: /subscriptions
31
+ # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
32
+ # Else, they will be the body of the request.
33
+ def list(options = {}, custom_headers = {})
34
+ path = '/subscriptions'
35
+
36
+ response = make_request(:get, path, options, custom_headers)
37
+ ListResponse.new(
38
+ raw_response: response,
39
+ unenveloped_body: unenvelope_body(response.body),
40
+ resource_class: Resources::Subscription
41
+ )
42
+ end
43
+
44
+ # Get a lazily enumerated list of all the items returned. This is simmilar to the `list` method but will paginate for you automatically.
45
+ #
46
+ # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
47
+ # Otherwise they will be the body of the request.
48
+ def all(options = {})
49
+ Paginator.new(
50
+ service: self,
51
+ path: '/subscriptions',
52
+ options: options
53
+ ).enumerator
54
+ end
55
+
56
+ # Retrieves the details of a single subscription.
57
+ # Example URL: /subscriptions/:identity
58
+ #
59
+ # @param identity # Unique identifier, beginning with "SB"
60
+ # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
61
+ # Else, they will be the body of the request.
62
+ def get(identity, options = {}, custom_headers = {})
63
+ path = sub_url('/subscriptions/:identity', 'identity' => identity)
64
+
65
+ response = make_request(:get, path, options, custom_headers)
66
+
67
+ Resources::Subscription.new(unenvelope_body(response.body))
68
+ end
69
+
70
+ # Updates a subscription object.
71
+ # Example URL: /subscriptions/:identity
72
+ #
73
+ # @param identity # Unique identifier, beginning with "SB"
74
+ # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
75
+ # Else, they will be the body of the request.
76
+ def update(identity, options = {}, custom_headers = {})
77
+ path = sub_url('/subscriptions/:identity', 'identity' => identity)
78
+
79
+ new_options = {}
80
+ new_options[envelope_key] = options
81
+ options = new_options
82
+ response = make_request(:put, path, options, custom_headers)
83
+
84
+ Resources::Subscription.new(unenvelope_body(response.body))
85
+ end
86
+
87
+ # Immediately cancels a subscription; no more payments will be created under it.
88
+ # Any metadata supplied to this endpoint will be stored on the payment
89
+ # cancellation event it causes.
90
+ #
91
+ # This will fail with a cancellation_failed
92
+ # error if the subscription is already cancelled or finished.
93
+ # Example URL: /subscriptions/:identity/actions/cancel
94
+ #
95
+ # @param identity # Unique identifier, beginning with "SB"
96
+ # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
97
+ # Else, they will be the body of the request.
98
+ def cancel(identity, options = {}, custom_headers = {})
99
+ path = sub_url('/subscriptions/:identity/actions/cancel', 'identity' => identity)
100
+
101
+ new_options = {}
102
+ new_options['data'] = options
103
+ options = new_options
104
+ response = make_request(:post, path, options, custom_headers)
105
+
106
+ Resources::Subscription.new(unenvelope_body(response.body))
107
+ end
108
+
109
+ # Unenvelope the response of the body using the service's `envelope_key`
110
+ #
111
+ # @param body [Hash]
112
+ def unenvelope_body(body)
113
+ body[envelope_key] || body['data']
114
+ end
115
+
116
+ private
117
+
118
+ # return the key which API responses will envelope data under
119
+ def envelope_key
120
+ 'subscriptions'
121
+ end
122
+
123
+ # take a URL with placeholder params and substitute them out for the acutal value
124
+ # @param url [String] the URL with placeholders in
125
+ # @param param_map [Hash] a hash of placeholders and their actual values
126
+ def sub_url(url, param_map)
127
+ param_map.reduce(url) do |new_url, (param, value)|
128
+ new_url.gsub(":#{param}", value)
129
+ end
130
+ end
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,148 @@
1
+ require_relative './base_service'
2
+
3
+ # encoding: utf-8
4
+ #
5
+ # WARNING: Do not edit by hand, this file was generated by Crank:
6
+ #
7
+ # https://github.com/gocardless/crank
8
+
9
+ module GoCardless
10
+ module Services
11
+ # Service for making requests to the User endpoints
12
+ class UserService < BaseService
13
+ # <a name="user_exists"></a>Creates a new user object. Email addresses must be
14
+ # unique.
15
+ # Example URL: /users
16
+ # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
17
+ # Else, they will be the body of the request.
18
+ def create(options = {}, custom_headers = {})
19
+ path = '/users'
20
+ new_options = {}
21
+ new_options[envelope_key] = options
22
+ options = new_options
23
+ response = make_request(:post, path, options, custom_headers)
24
+
25
+ Resources::User.new(unenvelope_body(response.body))
26
+ end
27
+
28
+ # Returns a
29
+ # [cursor-paginated](https://developer.gocardless.com/pro/#overview-cursor-pagination)
30
+ # list of your users.
31
+ # Example URL: /users
32
+ # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
33
+ # Else, they will be the body of the request.
34
+ def list(options = {}, custom_headers = {})
35
+ path = '/users'
36
+
37
+ response = make_request(:get, path, options, custom_headers)
38
+ ListResponse.new(
39
+ raw_response: response,
40
+ unenveloped_body: unenvelope_body(response.body),
41
+ resource_class: Resources::User
42
+ )
43
+ end
44
+
45
+ # Get a lazily enumerated list of all the items returned. This is simmilar to the `list` method but will paginate for you automatically.
46
+ #
47
+ # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
48
+ # Otherwise they will be the body of the request.
49
+ def all(options = {})
50
+ Paginator.new(
51
+ service: self,
52
+ path: '/users',
53
+ options: options
54
+ ).enumerator
55
+ end
56
+
57
+ # Retrieves the details of an existing user. In addition to the usual
58
+ # permissions based access rules, any user can access their own record.
59
+ # Example URL: /users/:identity
60
+ #
61
+ # @param identity # Unique identifier, beginning with "US"
62
+ # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
63
+ # Else, they will be the body of the request.
64
+ def get(identity, options = {}, custom_headers = {})
65
+ path = sub_url('/users/:identity', 'identity' => identity)
66
+
67
+ response = make_request(:get, path, options, custom_headers)
68
+
69
+ Resources::User.new(unenvelope_body(response.body))
70
+ end
71
+
72
+ # Updates a user object. Supports all of the fields supported when creating a
73
+ # user.
74
+ # Example URL: /users/:identity
75
+ #
76
+ # @param identity # Unique identifier, beginning with "US"
77
+ # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
78
+ # Else, they will be the body of the request.
79
+ def update(identity, options = {}, custom_headers = {})
80
+ path = sub_url('/users/:identity', 'identity' => identity)
81
+
82
+ new_options = {}
83
+ new_options[envelope_key] = options
84
+ options = new_options
85
+ response = make_request(:put, path, options, custom_headers)
86
+
87
+ Resources::User.new(unenvelope_body(response.body))
88
+ end
89
+
90
+ # Enables a user
91
+ # Example URL: /users/:identity/actions/enable
92
+ #
93
+ # @param identity # Unique identifier, beginning with "US"
94
+ # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
95
+ # Else, they will be the body of the request.
96
+ def enable(identity, options = {}, custom_headers = {})
97
+ path = sub_url('/users/:identity/actions/enable', 'identity' => identity)
98
+
99
+ new_options = {}
100
+ new_options['data'] = options
101
+ options = new_options
102
+ response = make_request(:post, path, options, custom_headers)
103
+
104
+ Resources::User.new(unenvelope_body(response.body))
105
+ end
106
+
107
+ # Disables a user
108
+ # Example URL: /users/:identity/actions/disable
109
+ #
110
+ # @param identity # Unique identifier, beginning with "US"
111
+ # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
112
+ # Else, they will be the body of the request.
113
+ def disable(identity, options = {}, custom_headers = {})
114
+ path = sub_url('/users/:identity/actions/disable', 'identity' => identity)
115
+
116
+ new_options = {}
117
+ new_options['data'] = options
118
+ options = new_options
119
+ response = make_request(:post, path, options, custom_headers)
120
+
121
+ Resources::User.new(unenvelope_body(response.body))
122
+ end
123
+
124
+ # Unenvelope the response of the body using the service's `envelope_key`
125
+ #
126
+ # @param body [Hash]
127
+ def unenvelope_body(body)
128
+ body[envelope_key] || body['data']
129
+ end
130
+
131
+ private
132
+
133
+ # return the key which API responses will envelope data under
134
+ def envelope_key
135
+ 'users'
136
+ end
137
+
138
+ # take a URL with placeholder params and substitute them out for the acutal value
139
+ # @param url [String] the URL with placeholders in
140
+ # @param param_map [Hash] a hash of placeholders and their actual values
141
+ def sub_url(url, param_map)
142
+ param_map.reduce(url) do |new_url, (param, value)|
143
+ new_url.gsub(":#{param}", value)
144
+ end
145
+ end
146
+ end
147
+ end
148
+ end