insightly2 0.1.4
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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/README.md +113 -0
- data/Rakefile +6 -0
- data/config/gem_secret.yml.example +1 -0
- data/insightly2.gemspec +29 -0
- data/lib/insightly2/client.rb +54 -0
- data/lib/insightly2/dsl/comments.rb +47 -0
- data/lib/insightly2/dsl/contacts.rb +130 -0
- data/lib/insightly2/dsl/countries.rb +12 -0
- data/lib/insightly2/dsl/currencies.rb +12 -0
- data/lib/insightly2/dsl/custom_fields.rb +22 -0
- data/lib/insightly2/dsl/emails.rb +57 -0
- data/lib/insightly2/dsl/events.rb +52 -0
- data/lib/insightly2/dsl/file_attachments.rb +14 -0
- data/lib/insightly2/dsl/file_categories.rb +52 -0
- data/lib/insightly2/dsl/notes.rb +85 -0
- data/lib/insightly2/dsl/opportunities.rb +134 -0
- data/lib/insightly2/dsl/opportunity_categories.rb +52 -0
- data/lib/insightly2/dsl/opportunity_state_reasons.rb +12 -0
- data/lib/insightly2/dsl/organisations.rb +128 -0
- data/lib/insightly2/dsl/pipeline_stages.rb +22 -0
- data/lib/insightly2/dsl/pipelines.rb +22 -0
- data/lib/insightly2/dsl/project_categories.rb +52 -0
- data/lib/insightly2/dsl/projects.rb +129 -0
- data/lib/insightly2/dsl/relationships.rb +12 -0
- data/lib/insightly2/dsl/tags.rb +15 -0
- data/lib/insightly2/dsl/task_categories.rb +52 -0
- data/lib/insightly2/dsl/tasks.rb +76 -0
- data/lib/insightly2/dsl/team_members.rb +53 -0
- data/lib/insightly2/dsl/teams.rb +53 -0
- data/lib/insightly2/dsl/users.rb +22 -0
- data/lib/insightly2/dsl.rb +65 -0
- data/lib/insightly2/errors/client_error.rb +10 -0
- data/lib/insightly2/errors/resource_not_found_error.rb +8 -0
- data/lib/insightly2/errors.rb +10 -0
- data/lib/insightly2/resources/comment.rb +10 -0
- data/lib/insightly2/resources/contact.rb +8 -0
- data/lib/insightly2/resources/country.rb +8 -0
- data/lib/insightly2/resources/currency.rb +8 -0
- data/lib/insightly2/resources/custom_field.rb +8 -0
- data/lib/insightly2/resources/email.rb +8 -0
- data/lib/insightly2/resources/event.rb +8 -0
- data/lib/insightly2/resources/file_attachment.rb +8 -0
- data/lib/insightly2/resources/file_category.rb +8 -0
- data/lib/insightly2/resources/note.rb +8 -0
- data/lib/insightly2/resources/object/attributes.rb +71 -0
- data/lib/insightly2/resources/object/serializers.rb +102 -0
- data/lib/insightly2/resources/object.rb +29 -0
- data/lib/insightly2/resources/opportunity.rb +8 -0
- data/lib/insightly2/resources/opportunity_category.rb +8 -0
- data/lib/insightly2/resources/opportunity_state_reason.rb +8 -0
- data/lib/insightly2/resources/organisation.rb +8 -0
- data/lib/insightly2/resources/pipeline.rb +8 -0
- data/lib/insightly2/resources/pipeline_stage.rb +8 -0
- data/lib/insightly2/resources/project.rb +8 -0
- data/lib/insightly2/resources/project_category.rb +8 -0
- data/lib/insightly2/resources/relationship.rb +8 -0
- data/lib/insightly2/resources/tag.rb +8 -0
- data/lib/insightly2/resources/task.rb +8 -0
- data/lib/insightly2/resources/task_category.rb +8 -0
- data/lib/insightly2/resources/team.rb +8 -0
- data/lib/insightly2/resources/team_member.rb +8 -0
- data/lib/insightly2/resources/user.rb +8 -0
- data/lib/insightly2/resources.rb +33 -0
- data/lib/insightly2/utils/url_helper.rb +17 -0
- data/lib/insightly2/utils.rb +8 -0
- data/lib/insightly2/version.rb +3 -0
- data/lib/insightly2.rb +22 -0
- data/spec/fixtures/vcr_cassettes/create_comment_attachment.yml +42 -0
- data/spec/fixtures/vcr_cassettes/create_contact.yml +47 -0
- data/spec/fixtures/vcr_cassettes/create_contact_image.yml +42 -0
- data/spec/fixtures/vcr_cassettes/create_email_comment.yml +47 -0
- data/spec/fixtures/vcr_cassettes/create_event.yml +95 -0
- data/spec/fixtures/vcr_cassettes/create_file_category.yml +89 -0
- data/spec/fixtures/vcr_cassettes/create_note.yml +95 -0
- data/spec/fixtures/vcr_cassettes/create_note_comment.yml +47 -0
- data/spec/fixtures/vcr_cassettes/create_note_file.yml +42 -0
- data/spec/fixtures/vcr_cassettes/create_opportunity.yml +98 -0
- data/spec/fixtures/vcr_cassettes/create_opportunity_category.yml +89 -0
- data/spec/fixtures/vcr_cassettes/create_opportunity_image.yml +42 -0
- data/spec/fixtures/vcr_cassettes/create_organisation.yml +116 -0
- data/spec/fixtures/vcr_cassettes/create_organisation_image.yml +42 -0
- data/spec/fixtures/vcr_cassettes/create_project.yml +106 -0
- data/spec/fixtures/vcr_cassettes/create_project_category.yml +89 -0
- data/spec/fixtures/vcr_cassettes/create_project_image.yml +42 -0
- data/spec/fixtures/vcr_cassettes/create_task.yml +98 -0
- data/spec/fixtures/vcr_cassettes/create_task_category.yml +89 -0
- data/spec/fixtures/vcr_cassettes/create_task_comment.yml +47 -0
- data/spec/fixtures/vcr_cassettes/create_team.yml +92 -0
- data/spec/fixtures/vcr_cassettes/create_team_member.yml +89 -0
- data/spec/fixtures/vcr_cassettes/delete_comment.yml +42 -0
- data/spec/fixtures/vcr_cassettes/delete_contact.yml +42 -0
- data/spec/fixtures/vcr_cassettes/delete_contact_image.yml +42 -0
- data/spec/fixtures/vcr_cassettes/delete_email.yml +42 -0
- data/spec/fixtures/vcr_cassettes/delete_event.yml +42 -0
- data/spec/fixtures/vcr_cassettes/delete_file_category.yml +42 -0
- data/spec/fixtures/vcr_cassettes/delete_note.yml +42 -0
- data/spec/fixtures/vcr_cassettes/delete_opportunity.yml +42 -0
- data/spec/fixtures/vcr_cassettes/delete_opportunity_category.yml +42 -0
- data/spec/fixtures/vcr_cassettes/delete_opportunity_image.yml +42 -0
- data/spec/fixtures/vcr_cassettes/delete_organisation.yml +42 -0
- data/spec/fixtures/vcr_cassettes/delete_organisation_image.yml +42 -0
- data/spec/fixtures/vcr_cassettes/delete_project.yml +42 -0
- data/spec/fixtures/vcr_cassettes/delete_project_category.yml +42 -0
- data/spec/fixtures/vcr_cassettes/delete_project_image.yml +42 -0
- data/spec/fixtures/vcr_cassettes/delete_task.yml +42 -0
- data/spec/fixtures/vcr_cassettes/delete_task_category.yml +42 -0
- data/spec/fixtures/vcr_cassettes/delete_team.yml +42 -0
- data/spec/fixtures/vcr_cassettes/delete_team_member.yml +42 -0
- data/spec/fixtures/vcr_cassettes/get_comment.yml +47 -0
- data/spec/fixtures/vcr_cassettes/get_contact.yml +47 -0
- data/spec/fixtures/vcr_cassettes/get_contact_emails.yml +47 -0
- data/spec/fixtures/vcr_cassettes/get_contact_image.yml +44 -0
- data/spec/fixtures/vcr_cassettes/get_contact_notes.yml +48 -0
- data/spec/fixtures/vcr_cassettes/get_contact_tasks.yml +48 -0
- data/spec/fixtures/vcr_cassettes/get_contacts.yml +184 -0
- data/spec/fixtures/vcr_cassettes/get_countries.yml +85 -0
- data/spec/fixtures/vcr_cassettes/get_currencies.yml +124 -0
- data/spec/fixtures/vcr_cassettes/get_custom_field.yml +46 -0
- data/spec/fixtures/vcr_cassettes/get_custom_fields.yml +46 -0
- data/spec/fixtures/vcr_cassettes/get_email.yml +48 -0
- data/spec/fixtures/vcr_cassettes/get_email_comments.yml +49 -0
- data/spec/fixtures/vcr_cassettes/get_emails.yml +47 -0
- data/spec/fixtures/vcr_cassettes/get_event.yml +48 -0
- data/spec/fixtures/vcr_cassettes/get_events.yml +48 -0
- data/spec/fixtures/vcr_cassettes/get_file_attachment.yml +4057 -0
- data/spec/fixtures/vcr_cassettes/get_file_categories.yml +46 -0
- data/spec/fixtures/vcr_cassettes/get_file_category.yml +46 -0
- data/spec/fixtures/vcr_cassettes/get_note.yml +48 -0
- data/spec/fixtures/vcr_cassettes/get_note_comments.yml +48 -0
- data/spec/fixtures/vcr_cassettes/get_notes.yml +52 -0
- data/spec/fixtures/vcr_cassettes/get_opportunities.yml +81 -0
- data/spec/fixtures/vcr_cassettes/get_opportunity.yml +49 -0
- data/spec/fixtures/vcr_cassettes/get_opportunity_categories.yml +46 -0
- data/spec/fixtures/vcr_cassettes/get_opportunity_category.yml +46 -0
- data/spec/fixtures/vcr_cassettes/get_opportunity_emails.yml +48 -0
- data/spec/fixtures/vcr_cassettes/get_opportunity_image.yml +44 -0
- data/spec/fixtures/vcr_cassettes/get_opportunity_notes.yml +48 -0
- data/spec/fixtures/vcr_cassettes/get_opportunity_state_history.yml +83 -0
- data/spec/fixtures/vcr_cassettes/get_opportunity_state_reasons.yml +47 -0
- data/spec/fixtures/vcr_cassettes/get_opportunity_tasks.yml +49 -0
- data/spec/fixtures/vcr_cassettes/get_organisation.yml +55 -0
- data/spec/fixtures/vcr_cassettes/get_organisation_emails.yml +48 -0
- data/spec/fixtures/vcr_cassettes/get_organisation_image.yml +42 -0
- data/spec/fixtures/vcr_cassettes/get_organisation_notes.yml +47 -0
- data/spec/fixtures/vcr_cassettes/get_organisation_tasks.yml +48 -0
- data/spec/fixtures/vcr_cassettes/get_organisations.yml +2092 -0
- data/spec/fixtures/vcr_cassettes/get_pipeline.yml +46 -0
- data/spec/fixtures/vcr_cassettes/get_pipeline_stage.yml +46 -0
- data/spec/fixtures/vcr_cassettes/get_pipeline_stages.yml +49 -0
- data/spec/fixtures/vcr_cassettes/get_pipelines.yml +46 -0
- data/spec/fixtures/vcr_cassettes/get_project.yml +52 -0
- data/spec/fixtures/vcr_cassettes/get_project_categories.yml +46 -0
- data/spec/fixtures/vcr_cassettes/get_project_category.yml +46 -0
- data/spec/fixtures/vcr_cassettes/get_project_emails.yml +48 -0
- data/spec/fixtures/vcr_cassettes/get_project_image.yml +44 -0
- data/spec/fixtures/vcr_cassettes/get_project_notes.yml +47 -0
- data/spec/fixtures/vcr_cassettes/get_project_tasks.yml +48 -0
- data/spec/fixtures/vcr_cassettes/get_projects.yml +52 -0
- data/spec/fixtures/vcr_cassettes/get_task.yml +49 -0
- data/spec/fixtures/vcr_cassettes/get_task_categories.yml +47 -0
- data/spec/fixtures/vcr_cassettes/get_task_category.yml +46 -0
- data/spec/fixtures/vcr_cassettes/get_task_comments.yml +47 -0
- data/spec/fixtures/vcr_cassettes/get_tasks.yml +148 -0
- data/spec/fixtures/vcr_cassettes/get_team.yml +47 -0
- data/spec/fixtures/vcr_cassettes/get_team_member.yml +46 -0
- data/spec/fixtures/vcr_cassettes/get_team_members.yml +46 -0
- data/spec/fixtures/vcr_cassettes/get_teams.yml +47 -0
- data/spec/fixtures/vcr_cassettes/get_user.yml +48 -0
- data/spec/fixtures/vcr_cassettes/get_users.yml +48 -0
- data/spec/fixtures/vcr_cassettes/update_comment.yml +97 -0
- data/spec/fixtures/vcr_cassettes/update_contact.yml +94 -0
- data/spec/fixtures/vcr_cassettes/update_contact_image.yml +42 -0
- data/spec/fixtures/vcr_cassettes/update_event.yml +97 -0
- data/spec/fixtures/vcr_cassettes/update_file_category.yml +91 -0
- data/spec/fixtures/vcr_cassettes/update_note.yml +100 -0
- data/spec/fixtures/vcr_cassettes/update_opportunity.yml +100 -0
- data/spec/fixtures/vcr_cassettes/update_opportunity_category.yml +91 -0
- data/spec/fixtures/vcr_cassettes/update_opportunity_image.yml +42 -0
- data/spec/fixtures/vcr_cassettes/update_organisation.yml +118 -0
- data/spec/fixtures/vcr_cassettes/update_organisation_image.yml +42 -0
- data/spec/fixtures/vcr_cassettes/update_project.yml +109 -0
- data/spec/fixtures/vcr_cassettes/update_project_category.yml +91 -0
- data/spec/fixtures/vcr_cassettes/update_project_image.yml +42 -0
- data/spec/fixtures/vcr_cassettes/update_task.yml +100 -0
- data/spec/fixtures/vcr_cassettes/update_task_category.yml +91 -0
- data/spec/fixtures/vcr_cassettes/update_team.yml +94 -0
- data/spec/fixtures/vcr_cassettes/update_team_member.yml +91 -0
- data/spec/fixtures/vcr_cassettes/z_insightly_client_status_check.yml +48 -0
- data/spec/insightly2/client_spec.rb +12 -0
- data/spec/insightly2/dsl/comments_spec.rb +45 -0
- data/spec/insightly2/dsl/contacts_spec.rb +130 -0
- data/spec/insightly2/dsl/countries_spec.rb +14 -0
- data/spec/insightly2/dsl/currencies_spec.rb +14 -0
- data/spec/insightly2/dsl/custom_fields_spec.rb +25 -0
- data/spec/insightly2/dsl/emails_spec.rb +56 -0
- data/spec/insightly2/dsl/events_spec.rb +55 -0
- data/spec/insightly2/dsl/file_attachments_spec.rb +15 -0
- data/spec/insightly2/dsl/file_categories_spec.rb +55 -0
- data/spec/insightly2/dsl/notes_spec.rb +86 -0
- data/spec/insightly2/dsl/opportunities_spec.rb +143 -0
- data/spec/insightly2/dsl/opportunity_categories_spec.rb +55 -0
- data/spec/insightly2/dsl/opportunity_state_reasons_spec.rb +14 -0
- data/spec/insightly2/dsl/organisations_spec.rb +131 -0
- data/spec/insightly2/dsl/pipeline_stages_spec.rb +25 -0
- data/spec/insightly2/dsl/pipelines_spec.rb +25 -0
- data/spec/insightly2/dsl/project_categories_spec.rb +55 -0
- data/spec/insightly2/dsl/projects_spec.rb +131 -0
- data/spec/insightly2/dsl/task_categories_spec.rb +55 -0
- data/spec/insightly2/dsl/tasks_spec.rb +75 -0
- data/spec/insightly2/dsl/team_members_spec.rb +56 -0
- data/spec/insightly2/dsl/teams_spec.rb +55 -0
- data/spec/insightly2/dsl/users_spec.rb +25 -0
- data/spec/insightly2/resources/comment_spec.rb +27 -0
- data/spec/insightly2/resources/contact_spec.rb +28 -0
- data/spec/insightly2/resources/custom_field_spec.rb +22 -0
- data/spec/insightly2/resources/email_spec.rb +29 -0
- data/spec/insightly2/resources/event_spec.rb +29 -0
- data/spec/insightly2/resources/file_attachment_spec.rb +31 -0
- data/spec/insightly2/resources/file_category_spec.rb +21 -0
- data/spec/insightly2/resources/note_spec.rb +29 -0
- data/spec/insightly2/resources/opportunity_category_spec.rb +21 -0
- data/spec/insightly2/resources/opportunity_spec.rb +30 -0
- data/spec/insightly2/resources/organisation_spec.rb +29 -0
- data/spec/insightly2/resources/pipeline_spec.rb +21 -0
- data/spec/insightly2/resources/pipeline_stage_spec.rb +21 -0
- data/spec/insightly2/resources/project_category_spec.rb +21 -0
- data/spec/insightly2/resources/project_spec.rb +30 -0
- data/spec/insightly2/resources/task_category_spec.rb +21 -0
- data/spec/insightly2/resources/task_spec.rb +32 -0
- data/spec/insightly2/resources/team_member_spec.rb +21 -0
- data/spec/insightly2/resources/team_spec.rb +27 -0
- data/spec/insightly2/resources/user_spec.rb +29 -0
- data/spec/insightly2_spec.rb +15 -0
- data/spec/spec_helper.rb +20 -0
- metadata +551 -0
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'insightly2/dsl'
|
2
|
+
|
3
|
+
module Insightly2
|
4
|
+
module DSL::TaskCategories
|
5
|
+
# GET /v2.1/TaskCategories/{id}
|
6
|
+
# Get a task category.
|
7
|
+
# @param [String, Fixnum] id A task category's ID.
|
8
|
+
# @raise [ArgumentError] If the method arguments are blank.
|
9
|
+
# @return [Insightly2::Resources::TaskCategory, nil].
|
10
|
+
def get_task_category(id:)
|
11
|
+
raise ArgumentError, "ID cannot be blank" if id.blank?
|
12
|
+
Resources::TaskCategory.parse(request(:get, "TaskCategories/#{id}"))
|
13
|
+
end
|
14
|
+
|
15
|
+
# GET /v2.1/TaskCategories
|
16
|
+
# Get a list of task categories.
|
17
|
+
# @return [Insightly2::Resources::TaskCategory, nil].
|
18
|
+
def get_task_categories
|
19
|
+
Resources::TaskCategory.parse(request(:get, "TaskCategories"))
|
20
|
+
end
|
21
|
+
|
22
|
+
# POST /v2.1/TaskCategories
|
23
|
+
# Creates a task category.
|
24
|
+
# @param [Hash] category The task category to create.
|
25
|
+
# @raise [ArgumentError] If the method arguments are blank.
|
26
|
+
# @return [Insightly2::Resources::TaskCategory, nil].
|
27
|
+
def create_task_category(category:)
|
28
|
+
raise ArgumentError, "Category cannot be blank" if category.blank?
|
29
|
+
Resources::TaskCategory.parse(request(:post, "TaskCategories", category))
|
30
|
+
end
|
31
|
+
|
32
|
+
# PUT /v2.1/TaskCategories
|
33
|
+
# Updates a task category.
|
34
|
+
# @param [Hash] category The task category to update.
|
35
|
+
# @raise [ArgumentError] If the method arguments are blank.
|
36
|
+
# @return [Insightly2::Resources::TaskCategory, nil].
|
37
|
+
def update_task_category(category:)
|
38
|
+
raise ArgumentError, "Category cannot be blank" if category.blank?
|
39
|
+
Resources::TaskCategory.parse(request(:put, "TaskCategories", category))
|
40
|
+
end
|
41
|
+
|
42
|
+
# DELETE /v2.1/TaskCategories/{id}
|
43
|
+
# Delete a task category.
|
44
|
+
# @param [String, Fixnum] id A task category's ID.
|
45
|
+
# @raise [ArgumentError] If the method arguments are blank.
|
46
|
+
# @return [Faraday::Response].
|
47
|
+
def delete_task_category(id:)
|
48
|
+
raise ArgumentError, "ID cannot be blank" if id.blank?
|
49
|
+
request(:delete, "TaskCategories/#{id}")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'insightly2/dsl'
|
2
|
+
|
3
|
+
module Insightly2
|
4
|
+
module DSL::Tasks
|
5
|
+
# GET /v2.1/Tasks/{id}
|
6
|
+
# Get a task.
|
7
|
+
# @param [String, Fixnum] id A Task's ID.
|
8
|
+
# @raise [ArgumentError] If the method arguments are blank.
|
9
|
+
# @return [Insightly2::Resources::Task, nil].
|
10
|
+
def get_task(id:)
|
11
|
+
raise ArgumentError, "ID cannot be blank" if id.blank?
|
12
|
+
Resources::Task.parse(request(:get, "Tasks/#{id}"))
|
13
|
+
end
|
14
|
+
|
15
|
+
# GET /v2.1/Tasks/{c_id}/Comments
|
16
|
+
# Get a list of comments for a task.
|
17
|
+
# @param [String, Fixnum] id A Task's ID.
|
18
|
+
# @raise [ArgumentError] If the method arguments are blank.
|
19
|
+
# @return [Array, nil].
|
20
|
+
def get_task_comments(id:)
|
21
|
+
raise ArgumentError, "ID cannot be blank" if id.blank?
|
22
|
+
Resources::Comment.parse(request(:get, "Tasks/#{id}/Comments"))
|
23
|
+
end
|
24
|
+
|
25
|
+
# GET /v2.1/Tasks?ids={ids}
|
26
|
+
# Get a list of tasks.
|
27
|
+
# @param [ids:] Array of task ids (optional).
|
28
|
+
# @return [Insightly2::Resources::Task, nil].
|
29
|
+
def get_tasks(ids: [])
|
30
|
+
url = Utils::UrlHelper.build_url(path: "Tasks", params: {ids: ids.join(',')})
|
31
|
+
Resources::Task.parse(request(:get, url))
|
32
|
+
end
|
33
|
+
|
34
|
+
# POST /v2.1/Tasks
|
35
|
+
# Create a task.
|
36
|
+
# @param [Hash] task The task to create.
|
37
|
+
# @raise [ArgumentError] If the method arguments are blank.
|
38
|
+
# @return [Insightly2::Resources::Task, nil].
|
39
|
+
def create_task(task:)
|
40
|
+
raise ArgumentError, "Task cannot be blank" if task.blank?
|
41
|
+
Resources::Task.parse(request(:post, "Tasks", task))
|
42
|
+
end
|
43
|
+
|
44
|
+
# POST /v2.1/Tasks/{c_id}/Comments
|
45
|
+
# Create a comment for a task.
|
46
|
+
# @param [String, Fixnum] id A task's ID.
|
47
|
+
# @param [Hash] comment The comment to create.
|
48
|
+
# @raise [ArgumentError] If the method arguments are blank.
|
49
|
+
# @return [Insightly2::Resources::Comment, nil].
|
50
|
+
def create_task_comment(id:, comment:)
|
51
|
+
raise ArgumentError, "ID cannot be blank" if id.blank?
|
52
|
+
raise ArgumentError, "Comment cannot be blank" if comment.blank?
|
53
|
+
Resources::Comment.parse(request(:post, "Tasks/#{id}/Comments", comment))
|
54
|
+
end
|
55
|
+
|
56
|
+
# PUT /v2.1/Tasks
|
57
|
+
# Update a task.
|
58
|
+
# @param [Hash] task The task to update.
|
59
|
+
# @raise [ArgumentError] If the method arguments are blank.
|
60
|
+
# @return [Insightly2::Resources::Comment, nil].
|
61
|
+
def update_task(task:)
|
62
|
+
raise ArgumentError, "Task cannot be blank" if task.blank?
|
63
|
+
Resources::Task.parse(request(:put, "Tasks", task))
|
64
|
+
end
|
65
|
+
|
66
|
+
# DELETE /v2.1/Tasks/{id}
|
67
|
+
# Delete a task.
|
68
|
+
# @param [String, Fixnum] id A Task's ID.
|
69
|
+
# @raise [ArgumentError] If the method arguments are blank.
|
70
|
+
# @return [Faraday::Response].
|
71
|
+
def delete_task(id:)
|
72
|
+
raise ArgumentError, "ID cannot be blank" if id.blank?
|
73
|
+
request(:delete, "Tasks/#{id}")
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'insightly2/dsl'
|
2
|
+
|
3
|
+
module Insightly2
|
4
|
+
module DSL::TeamMembers
|
5
|
+
# GET /v2.1/TeamMembers/{id}
|
6
|
+
# Get a team member.
|
7
|
+
# @param [String, Fixnum] id A team member's ID.
|
8
|
+
# @raise [ArgumentError] If the method arguments are blank.
|
9
|
+
# @return [Insightly2::Resources::TeamMember, nil].
|
10
|
+
def get_team_member(id:)
|
11
|
+
raise ArgumentError, "ID cannot be blank" if id.blank?
|
12
|
+
Resources::TeamMember.parse(request(:get, "TeamMembers/#{id}"))
|
13
|
+
end
|
14
|
+
|
15
|
+
# GET /v2.1/TeamMembers?teamid={teamid}
|
16
|
+
# Get a list of team members.
|
17
|
+
# @param [String, Fixnum] team_id: The ID of the team we're getting members for (optional).
|
18
|
+
# @return [Array, nil]
|
19
|
+
def get_team_members(team_id:)
|
20
|
+
Resources::TeamMember.parse(request(:get, "TeamMembers/?teamid=#{team_id}"))
|
21
|
+
end
|
22
|
+
|
23
|
+
# POST /v2.1/TeamMembers
|
24
|
+
# Create a team member.
|
25
|
+
# @param [Hash] team_member The team_member we're creating.
|
26
|
+
# @raise [ArgumentError] If the method arguments are blank.
|
27
|
+
# @return [Insightly2::Resources::TeamMember, nil].
|
28
|
+
def create_team_member(team_member:)
|
29
|
+
raise ArgumentError, "Team member cannot be blank" if team_member.blank?
|
30
|
+
Resources::TeamMember.parse(request(:post, "TeamMembers", team_member))
|
31
|
+
end
|
32
|
+
|
33
|
+
# PUT /v2.1/TeamMembers
|
34
|
+
# Update a team member.
|
35
|
+
# @param [Hash] team_member The team_member we're updating.
|
36
|
+
# @raise [ArgumentError] If the method arguments are blank.
|
37
|
+
# @return [Insightly2::Resources::TeamMember, nil].
|
38
|
+
def update_team_member(team_member:)
|
39
|
+
raise ArgumentError, "Team member cannot be blank" if team_member.blank?
|
40
|
+
Resources::TeamMember.parse(request(:put, "TeamMembers", team_member))
|
41
|
+
end
|
42
|
+
|
43
|
+
# DELETE /v2.1/TeamMembers/{id}
|
44
|
+
# Delete a team member.
|
45
|
+
# @param [String, Fixnum] id A team member's ID.
|
46
|
+
# @raise [ArgumentError] If the method arguments are blank.
|
47
|
+
# @return [Faraday::Response].
|
48
|
+
def delete_team_member(id:)
|
49
|
+
raise ArgumentError, "ID cannot be blank" if id.blank?
|
50
|
+
request(:delete, "TeamMembers/#{id}")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'insightly2/dsl'
|
2
|
+
|
3
|
+
module Insightly2
|
4
|
+
# https://api.insight.ly/v2.1/Help/ApiController/Teams
|
5
|
+
module DSL::Teams
|
6
|
+
# GET /v2.1/Teams/{id}
|
7
|
+
# Get a team.
|
8
|
+
# @param [String, Fixnum] id A team's ID.
|
9
|
+
# @raise [ArgumentError] If the method arguments are blank.
|
10
|
+
# @return [Insightly2::Resources::Team].
|
11
|
+
def get_team(id:)
|
12
|
+
raise ArgumentError, "ID cannot be blank" if id.blank?
|
13
|
+
Resources::Team.parse(request(:get, "Teams/#{id}"))
|
14
|
+
end
|
15
|
+
|
16
|
+
# GET /v2.1/Teams
|
17
|
+
# Get teams.
|
18
|
+
# @return [Array, nil].
|
19
|
+
def get_teams
|
20
|
+
Resources::Team.parse(request(:get, "Teams"))
|
21
|
+
end
|
22
|
+
|
23
|
+
# POST /v2.1/Teams
|
24
|
+
# Create a team.
|
25
|
+
# @param [Hash] team The team we're creating.
|
26
|
+
# @raise [ArgumentError] If the method arguments are blank.
|
27
|
+
# @return [Insightly2::Resources::Team, nil].
|
28
|
+
def create_team(team:)
|
29
|
+
raise ArgumentError, "Team cannot be blank" if team.blank?
|
30
|
+
Resources::Team.parse(request(:post, "Teams", team))
|
31
|
+
end
|
32
|
+
|
33
|
+
# PUT /v2.1/Teams
|
34
|
+
# Update a team..
|
35
|
+
# @param [Hash] team The team we're updating.
|
36
|
+
# @raise [ArgumentError] If the method arguments are blank.
|
37
|
+
# @return [Insightly2::Resources::Team, nil].
|
38
|
+
def update_team(team:)
|
39
|
+
raise ArgumentError, "Team cannot be blank" if team.blank?
|
40
|
+
Resources::Team.parse(request(:put, 'Teams', team))
|
41
|
+
end
|
42
|
+
|
43
|
+
# DELETE /v2.1/Teams/{id}
|
44
|
+
# Delete a team.
|
45
|
+
# @param [String, Fixnum] id A Team's ID.
|
46
|
+
# @raise [ArgumentError] If the method arguments are blank.
|
47
|
+
# @return [Faraday::Response].
|
48
|
+
def delete_team(id:)
|
49
|
+
raise ArgumentError, "ID cannot be blank" if id.blank?
|
50
|
+
request(:delete, "Teams/#{id}")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'insightly2/dsl'
|
2
|
+
|
3
|
+
module Insightly2
|
4
|
+
module DSL::Users
|
5
|
+
# GET /v2.1/Users/{id}
|
6
|
+
# Get a user.
|
7
|
+
# @param [String, Fixnum] id A user's ID.
|
8
|
+
# @raise [ArgumentError] If the method arguments are blank.
|
9
|
+
# @return [Insightly2::Resources::User, nil].
|
10
|
+
def get_user(id:)
|
11
|
+
raise ArgumentError, "ID cannot be blank" if id.blank?
|
12
|
+
Resources::User.parse(request(:get, "Users/#{id}"))
|
13
|
+
end
|
14
|
+
|
15
|
+
# GET /v2.1/Users
|
16
|
+
# Get a list of users.
|
17
|
+
# @return [Array, nil]
|
18
|
+
def get_users
|
19
|
+
Resources::User.parse(request(:get, "Users"))
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'insightly2'
|
2
|
+
|
3
|
+
module Insightly2
|
4
|
+
module DSL
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
require 'insightly2/dsl/comments'
|
9
|
+
require 'insightly2/dsl/contacts'
|
10
|
+
require 'insightly2/dsl/countries'
|
11
|
+
require 'insightly2/dsl/currencies'
|
12
|
+
require 'insightly2/dsl/custom_fields'
|
13
|
+
require 'insightly2/dsl/emails'
|
14
|
+
require 'insightly2/dsl/events'
|
15
|
+
require 'insightly2/dsl/file_attachments'
|
16
|
+
require 'insightly2/dsl/file_categories'
|
17
|
+
require 'insightly2/dsl/notes'
|
18
|
+
require 'insightly2/dsl/opportunities'
|
19
|
+
require 'insightly2/dsl/opportunity_categories'
|
20
|
+
require 'insightly2/dsl/opportunity_state_reasons'
|
21
|
+
require 'insightly2/dsl/organisations'
|
22
|
+
require 'insightly2/dsl/pipeline_stages'
|
23
|
+
require 'insightly2/dsl/pipelines'
|
24
|
+
require 'insightly2/dsl/project_categories'
|
25
|
+
require 'insightly2/dsl/projects'
|
26
|
+
require 'insightly2/dsl/relationships'
|
27
|
+
require 'insightly2/dsl/tags'
|
28
|
+
require 'insightly2/dsl/task_categories'
|
29
|
+
require 'insightly2/dsl/tasks'
|
30
|
+
require 'insightly2/dsl/team_members'
|
31
|
+
require 'insightly2/dsl/teams'
|
32
|
+
require 'insightly2/dsl/users'
|
33
|
+
require 'insightly2/utils'
|
34
|
+
|
35
|
+
module Insightly2
|
36
|
+
module DSL
|
37
|
+
include Comments
|
38
|
+
include Contacts
|
39
|
+
include Countries
|
40
|
+
include Currencies
|
41
|
+
include CustomFields
|
42
|
+
include Emails
|
43
|
+
include Events
|
44
|
+
include FileAttachments
|
45
|
+
include FileCategories
|
46
|
+
include Notes
|
47
|
+
include Opportunities
|
48
|
+
include OpportunityCategories
|
49
|
+
include OpportunityStateReasons
|
50
|
+
include Organisations
|
51
|
+
include PipelineStages
|
52
|
+
include Pipelines
|
53
|
+
include ProjectCategories
|
54
|
+
include Projects
|
55
|
+
include Relationships
|
56
|
+
include Tags
|
57
|
+
include TaskCategories
|
58
|
+
include Tasks
|
59
|
+
include TeamMembers
|
60
|
+
include Teams
|
61
|
+
include Users
|
62
|
+
include Utils
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module Insightly2::Resources::Object::Attributes
|
2
|
+
module ClassMethods
|
3
|
+
def attributes
|
4
|
+
@attributes ||=
|
5
|
+
begin
|
6
|
+
if superclass.respond_to?(:attributes)
|
7
|
+
superclass.attributes.dup
|
8
|
+
else
|
9
|
+
Hash.new { |hash, key| hash[key] = ::Object }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# @return [Module] module holding all attribute accessors
|
15
|
+
def attributes_module
|
16
|
+
@attributes_module ||= const_set(:AttributeMethods, Module.new)
|
17
|
+
end
|
18
|
+
|
19
|
+
def define_attribute_accessor(name, type = nil)
|
20
|
+
type ||= attributes[name.to_sym] || Object
|
21
|
+
attributes_module.send(:define_method, name) do
|
22
|
+
deserialize_attribute(name, type)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def attribute(name, type = String)
|
27
|
+
attributes[name] = type
|
28
|
+
|
29
|
+
define_attribute_accessor(name, type)
|
30
|
+
end
|
31
|
+
|
32
|
+
alias_method :has_many, :attribute
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.included(base)
|
36
|
+
base.extend(ClassMethods)
|
37
|
+
super
|
38
|
+
end
|
39
|
+
|
40
|
+
def attributes
|
41
|
+
{}.tap do |result|
|
42
|
+
__getobj__.keys.each do |key|
|
43
|
+
attribute = key.to_s.downcase
|
44
|
+
result[attribute] = public_send(attribute)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def method_missing(name, *args, &block)
|
50
|
+
attribute = name.to_s.upcase
|
51
|
+
if __getobj__.key?(attribute)
|
52
|
+
self.class.define_attribute_accessor(name)
|
53
|
+
deserialize_attribute(name, self.class.attributes[name.to_sym])
|
54
|
+
else
|
55
|
+
super
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def respond_to_missing?(name, include_all = false)
|
62
|
+
__getobj__.key?(name.to_s.upcase) || super(name, include_all)
|
63
|
+
end
|
64
|
+
|
65
|
+
# @param [String, Symbol] name
|
66
|
+
# @param [Class, #to_s] type
|
67
|
+
def deserialize_attribute(name, type)
|
68
|
+
raw = __getobj__[name.to_s.upcase]
|
69
|
+
self.class.serializer_for(type).deserialize(raw)
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'logger'
|
2
|
+
module Insightly2
|
3
|
+
module Resources
|
4
|
+
class Object
|
5
|
+
module Serializers
|
6
|
+
module Object
|
7
|
+
def self.serialize(value)
|
8
|
+
value.to_s
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.deserialize(value)
|
12
|
+
case value
|
13
|
+
when Array
|
14
|
+
value.map { |v| v.deep_transform_keys{ |key| key.downcase } }
|
15
|
+
when Hash
|
16
|
+
value.deep_transform_keys{ |key| key.downcase }
|
17
|
+
else
|
18
|
+
value
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
module Time
|
24
|
+
def self.serialize(value)
|
25
|
+
value.utc.xmlschema
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.deserialize(value)
|
29
|
+
::Time.parse(value)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
module ClassMethods
|
34
|
+
# @return [Hash] corresponding serializers for different attributes
|
35
|
+
def serializers
|
36
|
+
@serializers ||= {}
|
37
|
+
end
|
38
|
+
|
39
|
+
# @param [String, Symbol] type type of attribute to be serialized or deserialized
|
40
|
+
# @return [#serialize, #deserialize] serializer for provided type
|
41
|
+
def serializer_for(type)
|
42
|
+
serializers[type] ||=
|
43
|
+
begin
|
44
|
+
class_symbol = type.to_s.to_sym
|
45
|
+
if type.respond_to?(:deserialize) && type.respond_to?(:serialize)
|
46
|
+
type
|
47
|
+
elsif Serializers.constants.include?(class_symbol)
|
48
|
+
Serializers.const_get(class_symbol)
|
49
|
+
elsif Resources.constants.include?(class_symbol)
|
50
|
+
Resources.const_get(class_symbol)
|
51
|
+
else
|
52
|
+
Serializers::Object
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# Deserialize a Faraday response.
|
58
|
+
# @param [Faraday::Response] response.
|
59
|
+
# @raise [ArgumentError] If the response is blank.
|
60
|
+
# @return [Object, nil].
|
61
|
+
def deserialize(response)
|
62
|
+
raise ArgumentError, "Response cannot be blank" if response.blank?
|
63
|
+
|
64
|
+
attributes = response.body
|
65
|
+
begin
|
66
|
+
attributes = JSON.parse(response.body)
|
67
|
+
case attributes
|
68
|
+
when Array
|
69
|
+
return attributes.map { |object| new(object) }
|
70
|
+
when Hash
|
71
|
+
return new(attributes)
|
72
|
+
end
|
73
|
+
rescue JSON::ParserError
|
74
|
+
logger = Logger.new(STDOUT)
|
75
|
+
logger.error("Could not parse: #{response.body}")
|
76
|
+
end
|
77
|
+
nil
|
78
|
+
end
|
79
|
+
|
80
|
+
alias_method :parse, :deserialize
|
81
|
+
|
82
|
+
def serialize(object)
|
83
|
+
object.serialize
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.included(base)
|
88
|
+
super
|
89
|
+
base.extend ClassMethods
|
90
|
+
end
|
91
|
+
|
92
|
+
def serialize
|
93
|
+
{}.tap do |result|
|
94
|
+
attributes.each do |name, value|
|
95
|
+
result[name.upcase] = self.class.serializer_for(name).serialize(value)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'delegate'
|
2
|
+
require 'json'
|
3
|
+
require 'time'
|
4
|
+
|
5
|
+
module Insightly2
|
6
|
+
module Resources
|
7
|
+
class Object < SimpleDelegator
|
8
|
+
require 'insightly2/resources/object/serializers'
|
9
|
+
require 'insightly2/resources/object/attributes'
|
10
|
+
|
11
|
+
include Serializers
|
12
|
+
include Attributes
|
13
|
+
|
14
|
+
# Define common attributes, applicable to different resources
|
15
|
+
attribute :date_created_utc, Time
|
16
|
+
attribute :date_updated_utc, Time
|
17
|
+
|
18
|
+
def inspect
|
19
|
+
"#<#{self.class.name}:#{'0x00%x' % (object_id << 1)} #{inspect_attributes}>"
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def inspect_attributes
|
25
|
+
attributes.map { |key, value| "@#{key}=#{value.inspect}" }.join(' ')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|