basecrm 0.1.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +2 -2
- data/README.md +273 -17
- data/lib/basecrm.rb +185 -1
- data/lib/basecrm/configuration.rb +59 -0
- data/lib/basecrm/envelope.rb +7 -0
- data/lib/basecrm/errors.rb +65 -0
- data/lib/basecrm/http_client.rb +91 -0
- data/lib/basecrm/middlewares/oauth_bearer_token.rb +18 -0
- data/lib/basecrm/middlewares/raise_error.rb +31 -0
- data/lib/basecrm/model.rb +6 -0
- data/lib/basecrm/models/account.rb +31 -0
- data/lib/basecrm/models/address.rb +22 -0
- data/lib/basecrm/models/associated_contact.rb +19 -0
- data/lib/basecrm/models/contact.rb +88 -0
- data/lib/basecrm/models/deal.rb +58 -0
- data/lib/basecrm/models/lead.rb +79 -0
- data/lib/basecrm/models/loss_reason.rb +22 -0
- data/lib/basecrm/models/note.rb +28 -0
- data/lib/basecrm/models/pipeline.rb +19 -0
- data/lib/basecrm/models/source.rb +22 -0
- data/lib/basecrm/models/stage.rb +34 -0
- data/lib/basecrm/models/tag.rb +25 -0
- data/lib/basecrm/models/task.rb +46 -0
- data/lib/basecrm/models/user.rb +31 -0
- data/lib/basecrm/paginated_resource.rb +32 -0
- data/lib/basecrm/services/accounts_service.rb +33 -0
- data/lib/basecrm/services/associated_contacts_service.rb +91 -0
- data/lib/basecrm/services/contacts_service.rb +138 -0
- data/lib/basecrm/services/deals_service.rb +137 -0
- data/lib/basecrm/services/leads_service.rb +140 -0
- data/lib/basecrm/services/loss_reasons_service.rb +133 -0
- data/lib/basecrm/services/notes_service.rb +134 -0
- data/lib/basecrm/services/pipelines_service.rb +50 -0
- data/lib/basecrm/services/sources_service.rb +133 -0
- data/lib/basecrm/services/stages_service.rb +52 -0
- data/lib/basecrm/services/tags_service.rb +132 -0
- data/lib/basecrm/services/tasks_service.rb +141 -0
- data/lib/basecrm/services/users_service.rb +83 -0
- data/lib/basecrm/version.rb +3 -0
- data/spec/factories/associated_contact.rb +14 -0
- data/spec/factories/contact.rb +27 -0
- data/spec/factories/deal.rb +17 -0
- data/spec/factories/lead.rb +26 -0
- data/spec/factories/loss_reason.rb +11 -0
- data/spec/factories/note.rb +13 -0
- data/spec/factories/source.rb +11 -0
- data/spec/factories/tag.rb +12 -0
- data/spec/factories/task.rb +15 -0
- data/spec/services/accounts_service_spec.rb +16 -0
- data/spec/services/associated_contacts_service_spec.rb +43 -0
- data/spec/services/contacts_service_spec.rb +58 -0
- data/spec/services/deals_service_spec.rb +58 -0
- data/spec/services/leads_service_spec.rb +58 -0
- data/spec/services/loss_reasons_service_spec.rb +58 -0
- data/spec/services/notes_service_spec.rb +58 -0
- data/spec/services/pipelines_service_spec.rb +23 -0
- data/spec/services/sources_service_spec.rb +58 -0
- data/spec/services/stages_service_spec.rb +23 -0
- data/spec/services/tags_service_spec.rb +58 -0
- data/spec/services/tasks_service_spec.rb +58 -0
- data/spec/services/users_service_spec.rb +39 -0
- data/spec/spec_helper.rb +24 -12
- data/spec/support/client_helpers.rb +19 -0
- metadata +160 -71
- data/.gitignore +0 -20
- data/.rspec +0 -2
- data/.travis.yml +0 -6
- data/Gemfile +0 -4
- data/Rakefile +0 -8
- data/basecrm.gemspec +0 -23
- data/lib/base_crm.rb +0 -24
- data/lib/base_crm/account.rb +0 -11
- data/lib/base_crm/api_client_ext.rb +0 -6
- data/lib/base_crm/config.rb +0 -21
- data/lib/base_crm/contact.rb +0 -44
- data/lib/base_crm/custom_fieldable.rb +0 -32
- data/lib/base_crm/deal.rb +0 -50
- data/lib/base_crm/forecasting.rb +0 -12
- data/lib/base_crm/lead.rb +0 -36
- data/lib/base_crm/note.rb +0 -15
- data/lib/base_crm/noteable.rb +0 -15
- data/lib/base_crm/related_object_scope.rb +0 -35
- data/lib/base_crm/resource.rb +0 -14
- data/lib/base_crm/session.rb +0 -48
- data/lib/base_crm/source.rb +0 -14
- data/lib/base_crm/task.rb +0 -16
- data/lib/base_crm/taskable.rb +0 -15
- data/lib/base_crm/version.rb +0 -3
- data/spec/base_crm/account_spec.rb +0 -20
- data/spec/base_crm/contact_spec.rb +0 -92
- data/spec/base_crm/deal_spec.rb +0 -138
- data/spec/base_crm/forecasting_spec.rb +0 -34
- data/spec/base_crm/lead_spec.rb +0 -63
- data/spec/base_crm/note_spec.rb +0 -20
- data/spec/base_crm/resource_mixin_spec.rb +0 -26
- data/spec/base_crm/session_spec.rb +0 -97
- data/spec/base_crm/source_spec.rb +0 -20
- data/spec/base_crm/task_spec.rb +0 -21
- data/spec/support/noteable_shared_examples.rb +0 -64
- data/spec/support/taskable_shared_examples.rb +0 -69
@@ -0,0 +1,52 @@
|
|
1
|
+
# WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema
|
2
|
+
|
3
|
+
module BaseCRM
|
4
|
+
class StagesService
|
5
|
+
def initialize(client)
|
6
|
+
@client = client
|
7
|
+
end
|
8
|
+
|
9
|
+
# Retrieve all stages
|
10
|
+
#
|
11
|
+
# get '/stages'
|
12
|
+
#
|
13
|
+
# If you want to use filtering or sorting (see #where).
|
14
|
+
# @return [Enumerable] Paginated resource you can use to iterate over all the resources.
|
15
|
+
def all
|
16
|
+
PaginatedResource.new(self)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Retrieve all stages
|
20
|
+
#
|
21
|
+
# get '/stages'
|
22
|
+
#
|
23
|
+
# Returns all stages available to the user, according to the parameters provided
|
24
|
+
#
|
25
|
+
# @param options [Hash] Search options
|
26
|
+
# @option options [Boolean] :active Parameter that determines whether to return active or inactive stages. Unsupported for now.
|
27
|
+
# @option options [String] :ids Comma-separated list of stage IDs to be returned in a request.
|
28
|
+
# @option options [String] :name Name of the stage you're searching for. This parameter is used in a strict sense. Unsupported for now.
|
29
|
+
# @option options [Integer] :page (1) The page number to start from. Page numbering starts at 1, and omitting the `page` parameter will return the first page.
|
30
|
+
# @option options [Integer] :per_page (25) The number of records to return per page. The default limit is *25* and the maximum number that can be returned is *100*.
|
31
|
+
# @option options [Integer] :pipeline_id (1) The unique identifier of the pipeline that contains this stage.
|
32
|
+
# @option options [String] :sort_by (id:asc) Comma-separated list of fields to sort by. The sort criteria is applied in the order specified. The **default** ordering is **ascending**. If you want to change the sort ordering to descending, append `:desc` to the field e.g. `sort_by=position:desc`. Unsupported for now.
|
33
|
+
# @return [Array<Stage>] The list of Stages for the first page, unless otherwise specified.
|
34
|
+
def where(options = {})
|
35
|
+
_, _, root = @client.get("/stages", options)
|
36
|
+
|
37
|
+
root[:items].map{ |item| Stage.new(item[:data]) }
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
private
|
42
|
+
def validate_type!(stage)
|
43
|
+
raise TypeError unless stage.is_a?(Stage) || stage.is_a?(Hash)
|
44
|
+
end
|
45
|
+
|
46
|
+
def extract_params!(stage, *args)
|
47
|
+
params = stage.to_h.select{ |k, _| args.include?(k) }
|
48
|
+
raise ArgumentError, "one of required attributes is missing. Expected: #{args.join(',')}" if params.count != args.length
|
49
|
+
params
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
# WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema
|
2
|
+
|
3
|
+
module BaseCRM
|
4
|
+
class TagsService
|
5
|
+
OPTS_KEYS_TO_PERSIST = Set[:name, :resource_type]
|
6
|
+
|
7
|
+
def initialize(client)
|
8
|
+
@client = client
|
9
|
+
end
|
10
|
+
|
11
|
+
# Retrieve all tags
|
12
|
+
#
|
13
|
+
# get '/tags'
|
14
|
+
#
|
15
|
+
# If you want to use filtering or sorting (see #where).
|
16
|
+
# @return [Enumerable] Paginated resource you can use to iterate over all the resources.
|
17
|
+
def all
|
18
|
+
PaginatedResource.new(self)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Retrieve all tags
|
22
|
+
#
|
23
|
+
# get '/tags'
|
24
|
+
#
|
25
|
+
# Returns all tags available to the user, according to the parameters provided
|
26
|
+
#
|
27
|
+
# @param options [Hash] Search options
|
28
|
+
# @option options [Integer] :creator_id User ID. Returns all tags created by that user.
|
29
|
+
# @option options [String] :ids Comma-separated list of deal tag IDs to be returned in a request.
|
30
|
+
# @option options [String] :name Name of the tag to search for. This parameter is used in a strict sense.
|
31
|
+
# @option options [Integer] :page (1) Page number to start from. Page numbering starts at 1, and omitting the `page` parameter will return the first page.
|
32
|
+
# @option options [Integer] :per_page (25) Number of records to return per page. The default limit is *25* and the maximum number that can be returned is *100*.
|
33
|
+
# @option options [String] :resource_type Type name of resource to search for.
|
34
|
+
# @option options [String] :sort_by (updated_at:asc) A field to sort by. The **default** order is **ascending**. If you want to change the sort order to descending, append `:desc` to the field e.g. `sort_by=name:desc`.
|
35
|
+
# @return [Array<Tag>] The list of Tags for the first page, unless otherwise specified.
|
36
|
+
def where(options = {})
|
37
|
+
_, _, root = @client.get("/tags", options)
|
38
|
+
|
39
|
+
root[:items].map{ |item| Tag.new(item[:data]) }
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
# Create a tag
|
44
|
+
#
|
45
|
+
# post '/tags'
|
46
|
+
#
|
47
|
+
# Creates a new tag
|
48
|
+
# **Notice** the tag's name **must** be unique within the scope of the resource_type
|
49
|
+
#
|
50
|
+
# @param tag [Tag, Hash] Either object of the Tag type or Hash. This object's attributes describe the object to be created.
|
51
|
+
# @return [Tag] The resulting object represting created resource.
|
52
|
+
def create(tag)
|
53
|
+
validate_type!(tag)
|
54
|
+
|
55
|
+
attributes = sanitize(tag)
|
56
|
+
_, _, root = @client.post("/tags", attributes)
|
57
|
+
|
58
|
+
Tag.new(root[:data])
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
# Retrieve a single tag
|
63
|
+
#
|
64
|
+
# get '/tags/{id}'
|
65
|
+
#
|
66
|
+
# Returns a single tag available to the user according to the unique ID provided
|
67
|
+
# If the specified tag does not exist, this query will return an error
|
68
|
+
#
|
69
|
+
# @param id [Integer] Unique identifier of a Tag
|
70
|
+
# @return [Tag] Searched resource object.
|
71
|
+
def find(id)
|
72
|
+
_, _, root = @client.get("/tags/#{id}")
|
73
|
+
|
74
|
+
Tag.new(root[:data])
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
# Update a tag
|
79
|
+
#
|
80
|
+
# put '/tags/{id}'
|
81
|
+
#
|
82
|
+
# Updates a tag's information
|
83
|
+
# If the specified tag does not exist, this query will return an error
|
84
|
+
# **Notice** if you want to update a tag, you **must** make sure the tag's name is unique within the scope of the specified resource
|
85
|
+
#
|
86
|
+
# @param tag [Tag, Hash] Either object of the Tag type or Hash. This object's attributes describe the object to be updated.
|
87
|
+
# @return [Tag] The resulting object represting updated resource.
|
88
|
+
def update(tag)
|
89
|
+
validate_type!(tag)
|
90
|
+
params = extract_params!(tag, :id)
|
91
|
+
id = params[:id]
|
92
|
+
|
93
|
+
attributes = sanitize(tag)
|
94
|
+
_, _, root = @client.put("/tags/#{id}", attributes)
|
95
|
+
|
96
|
+
Tag.new(root[:data])
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
# Delete a tag
|
101
|
+
#
|
102
|
+
# delete '/tags/{id}'
|
103
|
+
#
|
104
|
+
# Deletes an existing tag
|
105
|
+
# If the specified tag is assigned to any resource, we will remove this tag from all such resources
|
106
|
+
# If the specified tag does not exist, this query will return an error
|
107
|
+
# This operation cannot be undone
|
108
|
+
#
|
109
|
+
# @param id [Integer] Unique identifier of a Tag
|
110
|
+
# @return [Boolean] Status of the operation.
|
111
|
+
def destroy(id)
|
112
|
+
status, _, _ = @client.delete("/tags/#{id}")
|
113
|
+
status == 204
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
private
|
118
|
+
def validate_type!(tag)
|
119
|
+
raise TypeError unless tag.is_a?(Tag) || tag.is_a?(Hash)
|
120
|
+
end
|
121
|
+
|
122
|
+
def extract_params!(tag, *args)
|
123
|
+
params = tag.to_h.select{ |k, _| args.include?(k) }
|
124
|
+
raise ArgumentError, "one of required attributes is missing. Expected: #{args.join(',')}" if params.count != args.length
|
125
|
+
params
|
126
|
+
end
|
127
|
+
|
128
|
+
def sanitize(tag)
|
129
|
+
tag.to_h.select { |k, _| OPTS_KEYS_TO_PERSIST.include?(k) }
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
@@ -0,0 +1,141 @@
|
|
1
|
+
# WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema
|
2
|
+
|
3
|
+
module BaseCRM
|
4
|
+
class TasksService
|
5
|
+
OPTS_KEYS_TO_PERSIST = Set[:completed, :content, :due_date, :owner_id, :remind_at, :resource_id, :resource_type]
|
6
|
+
|
7
|
+
def initialize(client)
|
8
|
+
@client = client
|
9
|
+
end
|
10
|
+
|
11
|
+
# Retrieve all tasks
|
12
|
+
#
|
13
|
+
# get '/tasks'
|
14
|
+
#
|
15
|
+
# If you want to use filtering or sorting (see #where).
|
16
|
+
# @return [Enumerable] Paginated resource you can use to iterate over all the resources.
|
17
|
+
def all
|
18
|
+
PaginatedResource.new(self)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Retrieve all tasks
|
22
|
+
#
|
23
|
+
# get '/tasks'
|
24
|
+
#
|
25
|
+
# Returns all tasks available to the user, according to the parameters provided
|
26
|
+
# If you ask for tasks without any parameter provided Base API will return you both **floating** and **related** tasks
|
27
|
+
# Although you can narrow the search set to either of them via query parameters
|
28
|
+
#
|
29
|
+
# @param options [Hash] Search options
|
30
|
+
# @option options [Boolean] :completed Indicates whether the query will return tasks that are completed or not.
|
31
|
+
# @option options [Integer] :creator_id Unique identifier of the user. Returns all tasks created by the user.
|
32
|
+
# @option options [String] :ids Comma-separated list of task IDs to be returned in a request.
|
33
|
+
# @option options [Boolean] :overdue Indicates whether the query will return tasks where the `due_date` parameter has been passed or not.
|
34
|
+
# @option options [Integer] :owner_id Unique identifier of the user. Returns all tasks owned by the user.
|
35
|
+
# @option options [Integer] :page (1) Page number to start from. Page numbering starts at 1 and omitting the `page` parameter will return the first page.
|
36
|
+
# @option options [Integer] :per_page (25) Number of records to return per page. The default limit is *25* and the maximum number that can be returned is *100*.
|
37
|
+
# @option options [String] :q A query string to search for. Performs a full text search on the `content` field.
|
38
|
+
# @option options [Boolean] :remind Indicates whether the query will return tasks with reminders or without reminders.
|
39
|
+
# @option options [Integer] :resource_id Unique identifier of the resource that you're searching for.
|
40
|
+
# @option options [String] :resource_type Name of the resource type to search for.
|
41
|
+
# @option options [String] :sort_by (updated_at:asc) A field to sort by. The **default** ordering is **ascending**. If you want to change the sort order to descending, append `:desc` to the field e.g. `sort_by=resource_type:desc`.
|
42
|
+
# @option options [String] :type Type of tasks to search for.
|
43
|
+
# @return [Array<Task>] The list of Tasks for the first page, unless otherwise specified.
|
44
|
+
def where(options = {})
|
45
|
+
_, _, root = @client.get("/tasks", options)
|
46
|
+
|
47
|
+
root[:items].map{ |item| Task.new(item[:data]) }
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
# Create a task
|
52
|
+
#
|
53
|
+
# post '/tasks'
|
54
|
+
#
|
55
|
+
# Creates a new task
|
56
|
+
# You can create either a **floating** task or create a **related** task and associate it with one of the resource types below:
|
57
|
+
# * [Leads](/docs/rest/reference/leads)
|
58
|
+
# * [Contacts](/docs/rest/reference/contacts)
|
59
|
+
# * [Deals](/docs/rest/reference/deals)
|
60
|
+
#
|
61
|
+
# @param task [Task, Hash] Either object of the Task type or Hash. This object's attributes describe the object to be created.
|
62
|
+
# @return [Task] The resulting object represting created resource.
|
63
|
+
def create(task)
|
64
|
+
validate_type!(task)
|
65
|
+
|
66
|
+
attributes = sanitize(task)
|
67
|
+
_, _, root = @client.post("/tasks", attributes)
|
68
|
+
|
69
|
+
Task.new(root[:data])
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
# Retrieve a single task
|
74
|
+
#
|
75
|
+
# get '/tasks/{id}'
|
76
|
+
#
|
77
|
+
# Returns a single task available to the user according to the unique task ID provided
|
78
|
+
# If the specified task does not exist, this query will return an error
|
79
|
+
#
|
80
|
+
# @param id [Integer] Unique identifier of a Task
|
81
|
+
# @return [Task] Searched resource object.
|
82
|
+
def find(id)
|
83
|
+
_, _, root = @client.get("/tasks/#{id}")
|
84
|
+
|
85
|
+
Task.new(root[:data])
|
86
|
+
end
|
87
|
+
|
88
|
+
|
89
|
+
# Update a task
|
90
|
+
#
|
91
|
+
# put '/tasks/{id}'
|
92
|
+
#
|
93
|
+
# Updates task information
|
94
|
+
# If the specified task does not exist, this query will return an error
|
95
|
+
#
|
96
|
+
# @param task [Task, Hash] Either object of the Task type or Hash. This object's attributes describe the object to be updated.
|
97
|
+
# @return [Task] The resulting object represting updated resource.
|
98
|
+
def update(task)
|
99
|
+
validate_type!(task)
|
100
|
+
params = extract_params!(task, :id)
|
101
|
+
id = params[:id]
|
102
|
+
|
103
|
+
attributes = sanitize(task)
|
104
|
+
_, _, root = @client.put("/tasks/#{id}", attributes)
|
105
|
+
|
106
|
+
Task.new(root[:data])
|
107
|
+
end
|
108
|
+
|
109
|
+
|
110
|
+
# Delete a task
|
111
|
+
#
|
112
|
+
# delete '/tasks/{id}'
|
113
|
+
#
|
114
|
+
# Delete an existing task
|
115
|
+
# If the specified task does not exist, this query will return an error
|
116
|
+
# This operation cannot be undone
|
117
|
+
#
|
118
|
+
# @param id [Integer] Unique identifier of a Task
|
119
|
+
# @return [Boolean] Status of the operation.
|
120
|
+
def destroy(id)
|
121
|
+
status, _, _ = @client.delete("/tasks/#{id}")
|
122
|
+
status == 204
|
123
|
+
end
|
124
|
+
|
125
|
+
|
126
|
+
private
|
127
|
+
def validate_type!(task)
|
128
|
+
raise TypeError unless task.is_a?(Task) || task.is_a?(Hash)
|
129
|
+
end
|
130
|
+
|
131
|
+
def extract_params!(task, *args)
|
132
|
+
params = task.to_h.select{ |k, _| args.include?(k) }
|
133
|
+
raise ArgumentError, "one of required attributes is missing. Expected: #{args.join(',')}" if params.count != args.length
|
134
|
+
params
|
135
|
+
end
|
136
|
+
|
137
|
+
def sanitize(task)
|
138
|
+
task.to_h.select { |k, _| OPTS_KEYS_TO_PERSIST.include?(k) }
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema
|
2
|
+
|
3
|
+
module BaseCRM
|
4
|
+
class UsersService
|
5
|
+
def initialize(client)
|
6
|
+
@client = client
|
7
|
+
end
|
8
|
+
|
9
|
+
# Retrieve all users
|
10
|
+
#
|
11
|
+
# get '/users'
|
12
|
+
#
|
13
|
+
# If you want to use filtering or sorting (see #where).
|
14
|
+
# @return [Enumerable] Paginated resource you can use to iterate over all the resources.
|
15
|
+
def all
|
16
|
+
PaginatedResource.new(self)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Retrieve all users
|
20
|
+
#
|
21
|
+
# get '/users'
|
22
|
+
#
|
23
|
+
# Returns all users, according to the parameters provided
|
24
|
+
#
|
25
|
+
# @param options [Hash] Search options
|
26
|
+
# @option options [Boolean] :confirmed Indicator whether to return only confirmed user accounts or not.
|
27
|
+
# @option options [String] :email Email of the user. This parameter is used in a strict sense.
|
28
|
+
# @option options [String] :ids Comma-separated list of user IDs to be returned in a request.
|
29
|
+
# @option options [String] :name Name of the user. This parameter is used in a strict sense.
|
30
|
+
# @option options [Integer] :page (1) Page number to start from. Page numbering starts at 1, and omitting the `page` parameter will return the first page.
|
31
|
+
# @option options [Integer] :per_page (25) Number of records to return per page. The default limit is *25*, and the maximum number that can be returned is *100*.
|
32
|
+
# @option options [String] :role Role of user to search for.
|
33
|
+
# @option options [String] :sort_by (id:asc) A field to sort by. The **default** order is **ascending**. If you want to change the sort order to descending, append `:desc` to the field e.g. `sort_by=name:desc`.
|
34
|
+
# @option options [String] :status Status of user accounts to search for.
|
35
|
+
# @return [Array<User>] The list of Users for the first page, unless otherwise specified.
|
36
|
+
def where(options = {})
|
37
|
+
_, _, root = @client.get("/users", options)
|
38
|
+
|
39
|
+
root[:items].map{ |item| User.new(item[:data]) }
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
# Retrieve a single user
|
44
|
+
#
|
45
|
+
# get '/users/{id}'
|
46
|
+
#
|
47
|
+
# Returns a single user according to the unique user ID provided
|
48
|
+
# If the specified user does not exist, this query returns an error
|
49
|
+
#
|
50
|
+
# @param id [Integer] Unique identifier of a User
|
51
|
+
# @return [User] Searched resource object.
|
52
|
+
def find(id)
|
53
|
+
_, _, root = @client.get("/users/#{id}")
|
54
|
+
|
55
|
+
User.new(root[:data])
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
# Retrieve an authenticating user
|
60
|
+
#
|
61
|
+
# get '/users/self'
|
62
|
+
#
|
63
|
+
# Returns a single authenticating user, according to the authentication credentials provided
|
64
|
+
#
|
65
|
+
# @return [User] Resource object.
|
66
|
+
def self
|
67
|
+
_, _, root = @client.get("/users/self")
|
68
|
+
User.new(root[:data])
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
private
|
73
|
+
def validate_type!(user)
|
74
|
+
raise TypeError unless user.is_a?(User) || user.is_a?(Hash)
|
75
|
+
end
|
76
|
+
|
77
|
+
def extract_params!(user, *args)
|
78
|
+
params = user.to_h.select{ |k, _| args.include?(k) }
|
79
|
+
raise ArgumentError, "one of required attributes is missing. Expected: #{args.join(',')}" if params.count != args.length
|
80
|
+
params
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
FactoryGirl.define do
|
2
|
+
factory :associated_contact, class: BaseCRM::AssociatedContact do
|
3
|
+
# transient attributes, required in url
|
4
|
+
deal_id nil
|
5
|
+
|
6
|
+
role { "involved" }
|
7
|
+
|
8
|
+
contact_id { contact.id }
|
9
|
+
|
10
|
+
to_create do |associated_contact|
|
11
|
+
client.associated_contacts.create(associated_contact.deal_id, associated_contact)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
FactoryGirl.define do
|
2
|
+
factory :contact, class: BaseCRM::Contact do
|
3
|
+
|
4
|
+
description { "I know him via Tom" }
|
5
|
+
email { "mark@designservices.com" }
|
6
|
+
facebook { "mjohnson" }
|
7
|
+
fax { "+44-208-1234567" }
|
8
|
+
first_name { Faker::Name.first_name }
|
9
|
+
industry { "Design Services" }
|
10
|
+
is_organization { false }
|
11
|
+
last_name { Faker::Name.last_name }
|
12
|
+
linkedin { "mjohnson" }
|
13
|
+
mobile { "508-778-6516" }
|
14
|
+
name { Faker::Name.name }
|
15
|
+
phone { "508-778-6516" }
|
16
|
+
skype { "mjohnson" }
|
17
|
+
tags { ["important"] }
|
18
|
+
title { "CEO" }
|
19
|
+
twitter { "mjohnson" }
|
20
|
+
website { "www.designservices.com" }
|
21
|
+
|
22
|
+
|
23
|
+
to_create do |contact|
|
24
|
+
client.contacts.create(contact)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|