Class: CrmpClient::Client
- Inherits:
-
Object
- Object
- CrmpClient::Client
- Defined in:
- lib/crmp_client/client.rb
Overview
This is the primary class provided by the CrmpClient gem, providing a wrapper to call various Crmp API endpoints.
This class provides methods which automatically deal with low-level concerns like paging of the Crmp API.
Instance Method Summary collapse
-
#area_containments(containing_area_identifier, contained_area_class, options = {}) ⇒ Object
Get all areas whose AreaClassification matches ‘contained_area_class`, and which are contained within the given `containing_area_identifier`.
-
#areas(area_class, options = {}) ⇒ Object
Get all areas of a specific AreaClassification.
-
#areas_with_memberships(area_class, options = {}) ⇒ Object
Get all areas of a specific AreaClassification, including memberships which represent each area.
-
#each_area(area_class, options = {}, &block) ⇒ Object
Iterate over all areas of a specific AreaClassification.
-
#each_area_containment(containing_area_identifier, contained_area_class, options = {}, &block) ⇒ Object
Iterate over all areas whose AreaClassification matches ‘contained_area_class`, and which are contained within the given `containing_area_identifier`.
-
#each_area_with_memberships(area_class, options = {}, &block) ⇒ Object
Iterate over all areas of a specific AreaClassification, including memberships which represent each area.
-
#each_list(options = {}, &block) ⇒ Object
Iterate over each list.
-
#each_list_item(list_id, options = {}, &block) ⇒ Object
Iterate over all items in a specific list.
-
#each_membership(organization_name, role_name, options = {}, &block) ⇒ Object
Iterate over all memberships whose Organisation matches the given ‘organization_name`, and whose Role matches the given `role_name`.
-
#initialize(base_uri, api_token) ⇒ Client
constructor
A new instance of Client.
-
#list_items(list_id, options = {}) ⇒ Object
Get all items which are in a specific list.
-
#lists(options = {}) ⇒ Object
Get all all lists.
-
#membership(identifier) ⇒ Object
Get a single Membership object, looking it up using it’s unique identifier.
-
#memberships(organization_name, role_name, options = {}) ⇒ Object
Get all memberships whose Organisation matches the given ‘organization_name`, and whose Role matches the given `role_name`.
Constructor Details
#initialize(base_uri, api_token) ⇒ Client
Returns a new instance of Client.
8 9 10 11 12 13 |
# File 'lib/crmp_client/client.rb', line 8 def initialize(base_uri, api_token) raise(ArgumentError, 'No base_uri - pass as param or set a default in initializer') unless base_uri raise(ArgumentError, 'No api_token - pass as param or set a default in initializer') unless api_token @api = CrmpClient::Api.new(base_uri, api_token) end |
Instance Method Details
#area_containments(containing_area_identifier, contained_area_class, options = {}) ⇒ Object
Get all areas whose AreaClassification matches ‘contained_area_class`, and which are contained within the given `containing_area_identifier`. Each area returned will also include a list of all areas which contain it.
101 102 103 104 105 106 107 |
# File 'lib/crmp_client/client.rb', line 101 def area_containments(containing_area_identifier, contained_area_class, = {}) @api.collect_api_call( 'areas/containments.json', { containing_area: containing_area_identifier, contained_area_classification: contained_area_class }, ) end |
#areas(area_class, options = {}) ⇒ Object
Get all areas of a specific AreaClassification
80 81 82 |
# File 'lib/crmp_client/client.rb', line 80 def areas(area_class, = {}) @api.collect_api_call('areas.json', { area_classification: area_class }, ) end |
#areas_with_memberships(area_class, options = {}) ⇒ Object
Get all areas of a specific AreaClassification, including memberships which represent each area
90 91 92 |
# File 'lib/crmp_client/client.rb', line 90 def areas_with_memberships(area_class, = {}) @api.collect_api_call('areas/memberships.json', { area_classification: area_class }, ) end |
#each_area(area_class, options = {}, &block) ⇒ Object
Iterate over all areas of a specific AreaClassification
85 86 87 |
# File 'lib/crmp_client/client.rb', line 85 def each_area(area_class, = {}, &block) @api.each_api_call('areas.json', { area_classification: area_class }, , block) end |
#each_area_containment(containing_area_identifier, contained_area_class, options = {}, &block) ⇒ Object
Iterate over all areas whose AreaClassification matches ‘contained_area_class`, and which are contained within the given `containing_area_identifier`. Each area returned will also include a list of all areas which contain it.
111 112 113 114 115 116 117 118 |
# File 'lib/crmp_client/client.rb', line 111 def each_area_containment(containing_area_identifier, contained_area_class, = {}, &block) @api.each_api_call( 'areas/containments.json', { containing_area: containing_area_identifier, contained_area_classification: contained_area_class }, , block ) end |
#each_area_with_memberships(area_class, options = {}, &block) ⇒ Object
Iterate over all areas of a specific AreaClassification, including memberships which represent each area
95 96 97 |
# File 'lib/crmp_client/client.rb', line 95 def each_area_with_memberships(area_class, = {}, &block) @api.each_api_call('areas/memberships.json', { area_classification: area_class }, , block) end |
#each_list(options = {}, &block) ⇒ Object
Iterate over each list
65 66 67 |
# File 'lib/crmp_client/client.rb', line 65 def each_list( = {}, &block) @api.each_api_call('lists.json', {}, , block) end |
#each_list_item(list_id, options = {}, &block) ⇒ Object
Iterate over all items in a specific list
75 76 77 |
# File 'lib/crmp_client/client.rb', line 75 def each_list_item(list_id, = {}, &block) @api.each_api_call('list/items.json', { list_id: list_id }, , block) end |
#each_membership(organization_name, role_name, options = {}, &block) ⇒ Object
Iterate over all memberships whose Organisation matches the given ‘organization_name`, and whose Role matches the given `role_name`. Both `organization_name` & `role_name` are optional, eg. if `role_name` is omitted then only `organization_name` is used to search for memberships.
55 56 57 |
# File 'lib/crmp_client/client.rb', line 55 def each_membership(organization_name, role_name, = {}, &block) @api.each_api_call('memberships.json', { organization: organization_name, role: role_name }, , block) end |
#list_items(list_id, options = {}) ⇒ Object
Get all items which are in a specific list
70 71 72 |
# File 'lib/crmp_client/client.rb', line 70 def list_items(list_id, = {}) @api.collect_api_call('list/items.json', { list_id: list_id }, ) end |
#lists(options = {}) ⇒ Object
Get all all lists
60 61 62 |
# File 'lib/crmp_client/client.rb', line 60 def lists( = {}) @api.collect_api_call('lists.json', {}, ).sort_by { |list| list['created_at'] } end |
#membership(identifier) ⇒ Object
Get a single Membership object, looking it up using it’s unique identifier
20 21 22 |
# File 'lib/crmp_client/client.rb', line 20 def membership(identifier) @api.raw_api_call('membership.json', { identifier: identifier }) end |
#memberships(organization_name, role_name, options = {}) ⇒ Object
Get all memberships whose Organisation matches the given ‘organization_name`, and whose Role matches the given `role_name`. Both `organization_name` & `role_name` are optional, eg. if `role_name` is omitted then only `organization_name` is used to search for memberships.
48 49 50 |
# File 'lib/crmp_client/client.rb', line 48 def memberships(organization_name, role_name, = {}) @api.collect_api_call('memberships.json', { organization: organization_name, role: role_name }, ) end |