basecrm 0.1.2 → 1.0.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 (101) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +2 -2
  3. data/README.md +273 -17
  4. data/lib/basecrm.rb +185 -1
  5. data/lib/basecrm/configuration.rb +59 -0
  6. data/lib/basecrm/envelope.rb +7 -0
  7. data/lib/basecrm/errors.rb +65 -0
  8. data/lib/basecrm/http_client.rb +91 -0
  9. data/lib/basecrm/middlewares/oauth_bearer_token.rb +18 -0
  10. data/lib/basecrm/middlewares/raise_error.rb +31 -0
  11. data/lib/basecrm/model.rb +6 -0
  12. data/lib/basecrm/models/account.rb +31 -0
  13. data/lib/basecrm/models/address.rb +22 -0
  14. data/lib/basecrm/models/associated_contact.rb +19 -0
  15. data/lib/basecrm/models/contact.rb +88 -0
  16. data/lib/basecrm/models/deal.rb +58 -0
  17. data/lib/basecrm/models/lead.rb +79 -0
  18. data/lib/basecrm/models/loss_reason.rb +22 -0
  19. data/lib/basecrm/models/note.rb +28 -0
  20. data/lib/basecrm/models/pipeline.rb +19 -0
  21. data/lib/basecrm/models/source.rb +22 -0
  22. data/lib/basecrm/models/stage.rb +34 -0
  23. data/lib/basecrm/models/tag.rb +25 -0
  24. data/lib/basecrm/models/task.rb +46 -0
  25. data/lib/basecrm/models/user.rb +31 -0
  26. data/lib/basecrm/paginated_resource.rb +32 -0
  27. data/lib/basecrm/services/accounts_service.rb +33 -0
  28. data/lib/basecrm/services/associated_contacts_service.rb +91 -0
  29. data/lib/basecrm/services/contacts_service.rb +138 -0
  30. data/lib/basecrm/services/deals_service.rb +137 -0
  31. data/lib/basecrm/services/leads_service.rb +140 -0
  32. data/lib/basecrm/services/loss_reasons_service.rb +133 -0
  33. data/lib/basecrm/services/notes_service.rb +134 -0
  34. data/lib/basecrm/services/pipelines_service.rb +50 -0
  35. data/lib/basecrm/services/sources_service.rb +133 -0
  36. data/lib/basecrm/services/stages_service.rb +52 -0
  37. data/lib/basecrm/services/tags_service.rb +132 -0
  38. data/lib/basecrm/services/tasks_service.rb +141 -0
  39. data/lib/basecrm/services/users_service.rb +83 -0
  40. data/lib/basecrm/version.rb +3 -0
  41. data/spec/factories/associated_contact.rb +14 -0
  42. data/spec/factories/contact.rb +27 -0
  43. data/spec/factories/deal.rb +17 -0
  44. data/spec/factories/lead.rb +26 -0
  45. data/spec/factories/loss_reason.rb +11 -0
  46. data/spec/factories/note.rb +13 -0
  47. data/spec/factories/source.rb +11 -0
  48. data/spec/factories/tag.rb +12 -0
  49. data/spec/factories/task.rb +15 -0
  50. data/spec/services/accounts_service_spec.rb +16 -0
  51. data/spec/services/associated_contacts_service_spec.rb +43 -0
  52. data/spec/services/contacts_service_spec.rb +58 -0
  53. data/spec/services/deals_service_spec.rb +58 -0
  54. data/spec/services/leads_service_spec.rb +58 -0
  55. data/spec/services/loss_reasons_service_spec.rb +58 -0
  56. data/spec/services/notes_service_spec.rb +58 -0
  57. data/spec/services/pipelines_service_spec.rb +23 -0
  58. data/spec/services/sources_service_spec.rb +58 -0
  59. data/spec/services/stages_service_spec.rb +23 -0
  60. data/spec/services/tags_service_spec.rb +58 -0
  61. data/spec/services/tasks_service_spec.rb +58 -0
  62. data/spec/services/users_service_spec.rb +39 -0
  63. data/spec/spec_helper.rb +24 -12
  64. data/spec/support/client_helpers.rb +19 -0
  65. metadata +160 -71
  66. data/.gitignore +0 -20
  67. data/.rspec +0 -2
  68. data/.travis.yml +0 -6
  69. data/Gemfile +0 -4
  70. data/Rakefile +0 -8
  71. data/basecrm.gemspec +0 -23
  72. data/lib/base_crm.rb +0 -24
  73. data/lib/base_crm/account.rb +0 -11
  74. data/lib/base_crm/api_client_ext.rb +0 -6
  75. data/lib/base_crm/config.rb +0 -21
  76. data/lib/base_crm/contact.rb +0 -44
  77. data/lib/base_crm/custom_fieldable.rb +0 -32
  78. data/lib/base_crm/deal.rb +0 -50
  79. data/lib/base_crm/forecasting.rb +0 -12
  80. data/lib/base_crm/lead.rb +0 -36
  81. data/lib/base_crm/note.rb +0 -15
  82. data/lib/base_crm/noteable.rb +0 -15
  83. data/lib/base_crm/related_object_scope.rb +0 -35
  84. data/lib/base_crm/resource.rb +0 -14
  85. data/lib/base_crm/session.rb +0 -48
  86. data/lib/base_crm/source.rb +0 -14
  87. data/lib/base_crm/task.rb +0 -16
  88. data/lib/base_crm/taskable.rb +0 -15
  89. data/lib/base_crm/version.rb +0 -3
  90. data/spec/base_crm/account_spec.rb +0 -20
  91. data/spec/base_crm/contact_spec.rb +0 -92
  92. data/spec/base_crm/deal_spec.rb +0 -138
  93. data/spec/base_crm/forecasting_spec.rb +0 -34
  94. data/spec/base_crm/lead_spec.rb +0 -63
  95. data/spec/base_crm/note_spec.rb +0 -20
  96. data/spec/base_crm/resource_mixin_spec.rb +0 -26
  97. data/spec/base_crm/session_spec.rb +0 -97
  98. data/spec/base_crm/source_spec.rb +0 -20
  99. data/spec/base_crm/task_spec.rb +0 -21
  100. data/spec/support/noteable_shared_examples.rb +0 -64
  101. data/spec/support/taskable_shared_examples.rb +0 -69
@@ -0,0 +1,133 @@
1
+ # WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema
2
+
3
+ module BaseCRM
4
+ class LossReasonsService
5
+ OPTS_KEYS_TO_PERSIST = Set[:name]
6
+
7
+ def initialize(client)
8
+ @client = client
9
+ end
10
+
11
+ # Retrieve all reasons
12
+ #
13
+ # get '/loss_reasons'
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 reasons
22
+ #
23
+ # get '/loss_reasons'
24
+ #
25
+ # Returns all deal loss reasons available to the user according to the parameters provided
26
+ #
27
+ # @param options [Hash] Search options
28
+ # @option options [String] :ids Comma separated list of deal loss reasons unique identifiers to be returned in a request.
29
+ # @option options [String] :name Name of the loss reason to search for. This parameter is used in a strict sense.
30
+ # @option options [Integer] :page (1) Page number to start from. Page numbering is 1-based and omitting `page` parameter will return the first page.
31
+ # @option options [Integer] :per_page (25) Number of records to return per page. Default limit is *25* and maximum number that can be returned is *100*.
32
+ # @option options [String] :sort_by (id:asc) A field to sort by. **Default** ordering is **ascending**. If you want to change the sort ordering to descending, append `:desc` to the field e.g. `sort_by=name:desc`.
33
+ # @return [Array<LossReason>] The list of LossReasons for the first page, unless otherwise specified.
34
+ def where(options = {})
35
+ _, _, root = @client.get("/loss_reasons", options)
36
+
37
+ root[:items].map{ |item| LossReason.new(item[:data]) }
38
+ end
39
+
40
+
41
+ # Create a loss reason
42
+ #
43
+ # post '/loss_reasons'
44
+ #
45
+ # Create a new loss reason
46
+ # <figure class="notice">
47
+ # Loss reason's name **must** be unique
48
+ # </figure>
49
+ #
50
+ # @param loss_reason [LossReason, Hash] Either object of the LossReason type or Hash. This object's attributes describe the object to be created.
51
+ # @return [LossReason] The resulting object represting created resource.
52
+ def create(loss_reason)
53
+ validate_type!(loss_reason)
54
+
55
+ attributes = sanitize(loss_reason)
56
+ _, _, root = @client.post("/loss_reasons", attributes)
57
+
58
+ LossReason.new(root[:data])
59
+ end
60
+
61
+
62
+ # Retrieve a single reason
63
+ #
64
+ # get '/loss_reasons/{id}'
65
+ #
66
+ # Returns a single loss reason available to the user by the provided id
67
+ # If a loss reason with the supplied unique identifier does not exist, it returns an error
68
+ #
69
+ # @param id [Integer] Unique identifier of a LossReason
70
+ # @return [LossReason] Searched resource object.
71
+ def find(id)
72
+ _, _, root = @client.get("/loss_reasons/#{id}")
73
+
74
+ LossReason.new(root[:data])
75
+ end
76
+
77
+
78
+ # Update a loss reason
79
+ #
80
+ # put '/loss_reasons/{id}'
81
+ #
82
+ # Updates a loss reason information
83
+ # If the specified loss reason does not exist, the request will return an error
84
+ # <figure class="notice">
85
+ # If you want to update loss reason you **must** make sure name of the reason is unique
86
+ # </figure>
87
+ #
88
+ # @param loss_reason [LossReason, Hash] Either object of the LossReason type or Hash. This object's attributes describe the object to be updated.
89
+ # @return [LossReason] The resulting object represting updated resource.
90
+ def update(loss_reason)
91
+ validate_type!(loss_reason)
92
+ params = extract_params!(loss_reason, :id)
93
+ id = params[:id]
94
+
95
+ attributes = sanitize(loss_reason)
96
+ _, _, root = @client.put("/loss_reasons/#{id}", attributes)
97
+
98
+ LossReason.new(root[:data])
99
+ end
100
+
101
+
102
+ # Delete a reason
103
+ #
104
+ # delete '/loss_reasons/{id}'
105
+ #
106
+ # Delete an existing loss reason
107
+ # If the reason with supplied unique identifier does not exist it returns an error
108
+ # This operation cannot be undone
109
+ #
110
+ # @param id [Integer] Unique identifier of a LossReason
111
+ # @return [Boolean] Status of the operation.
112
+ def destroy(id)
113
+ status, _, _ = @client.delete("/loss_reasons/#{id}")
114
+ status == 204
115
+ end
116
+
117
+
118
+ private
119
+ def validate_type!(loss_reason)
120
+ raise TypeError unless loss_reason.is_a?(LossReason) || loss_reason.is_a?(Hash)
121
+ end
122
+
123
+ def extract_params!(loss_reason, *args)
124
+ params = loss_reason.to_h.select{ |k, _| args.include?(k) }
125
+ raise ArgumentError, "one of required attributes is missing. Expected: #{args.join(',')}" if params.count != args.length
126
+ params
127
+ end
128
+
129
+ def sanitize(loss_reason)
130
+ loss_reason.to_h.select { |k, _| OPTS_KEYS_TO_PERSIST.include?(k) }
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,134 @@
1
+ # WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema
2
+
3
+ module BaseCRM
4
+ class NotesService
5
+ OPTS_KEYS_TO_PERSIST = Set[:content, :resource_id, :resource_type]
6
+
7
+ def initialize(client)
8
+ @client = client
9
+ end
10
+
11
+ # Retrieve all notes
12
+ #
13
+ # get '/notes'
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 notes
22
+ #
23
+ # get '/notes'
24
+ #
25
+ # Returns all notes available to the user, according to the parameters provided
26
+ #
27
+ # @param options [Hash] Search options
28
+ # @option options [Integer] :creator_id Unique identifier of the user. Returns all notes created by the user.
29
+ # @option options [String] :ids Comma-separated list of note IDs to be returned in a request.
30
+ # @option options [String] :includes Comma-separated list of one or more resources related to the note. **Not supported at the moment**.
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 at one time is *100*.
33
+ # @option options [String] :q A query string to search for. Performs a full text search on the `content` field.
34
+ # @option options [Integer] :resource_id Unique identifier of the resource to search for.
35
+ # @option options [String] :resource_type Name of the type of resource to search for.
36
+ # @option options [String] :sort_by (updated_at:asc) A field to sort by. **Default** ordering is **ascending**. If you want to change the sort ordering to descending, append `:desc` to the field e.g. `sort_by=resource_type:desc`.
37
+ # @return [Array<Note>] The list of Notes for the first page, unless otherwise specified.
38
+ def where(options = {})
39
+ _, _, root = @client.get("/notes", options)
40
+
41
+ root[:items].map{ |item| Note.new(item[:data]) }
42
+ end
43
+
44
+
45
+ # Create a note
46
+ #
47
+ # post '/notes'
48
+ #
49
+ # Create a new note and associate it with one of the resources listed below:
50
+ # * [Leads](/docs/rest/reference/leads)
51
+ # * [Contacts](/docs/rest/reference/contacts)
52
+ # * [Deals](/docs/rest/reference/deals)
53
+ #
54
+ # @param note [Note, Hash] Either object of the Note type or Hash. This object's attributes describe the object to be created.
55
+ # @return [Note] The resulting object represting created resource.
56
+ def create(note)
57
+ validate_type!(note)
58
+
59
+ attributes = sanitize(note)
60
+ _, _, root = @client.post("/notes", attributes)
61
+
62
+ Note.new(root[:data])
63
+ end
64
+
65
+
66
+ # Retrieve a single note
67
+ #
68
+ # get '/notes/{id}'
69
+ #
70
+ # Returns a single note available to the user, according to the unique note ID provided
71
+ # If the note ID does not exist, this request will return an error
72
+ #
73
+ # @param id [Integer] Unique identifier of a Note
74
+ # @return [Note] Searched resource object.
75
+ def find(id)
76
+ _, _, root = @client.get("/notes/#{id}")
77
+
78
+ Note.new(root[:data])
79
+ end
80
+
81
+
82
+ # Update a note
83
+ #
84
+ # put '/notes/{id}'
85
+ #
86
+ # Updates note information
87
+ # If the note ID does not exist, this request will return an error
88
+ #
89
+ # @param note [Note, Hash] Either object of the Note type or Hash. This object's attributes describe the object to be updated.
90
+ # @return [Note] The resulting object represting updated resource.
91
+ def update(note)
92
+ validate_type!(note)
93
+ params = extract_params!(note, :id)
94
+ id = params[:id]
95
+
96
+ attributes = sanitize(note)
97
+ _, _, root = @client.put("/notes/#{id}", attributes)
98
+
99
+ Note.new(root[:data])
100
+ end
101
+
102
+
103
+ # Delete a note
104
+ #
105
+ # delete '/notes/{id}'
106
+ #
107
+ # Delete an existing note
108
+ # If the note ID does not exist, this request will return an error
109
+ # This operation cannot be undone
110
+ #
111
+ # @param id [Integer] Unique identifier of a Note
112
+ # @return [Boolean] Status of the operation.
113
+ def destroy(id)
114
+ status, _, _ = @client.delete("/notes/#{id}")
115
+ status == 204
116
+ end
117
+
118
+
119
+ private
120
+ def validate_type!(note)
121
+ raise TypeError unless note.is_a?(Note) || note.is_a?(Hash)
122
+ end
123
+
124
+ def extract_params!(note, *args)
125
+ params = note.to_h.select{ |k, _| args.include?(k) }
126
+ raise ArgumentError, "one of required attributes is missing. Expected: #{args.join(',')}" if params.count != args.length
127
+ params
128
+ end
129
+
130
+ def sanitize(note)
131
+ note.to_h.select { |k, _| OPTS_KEYS_TO_PERSIST.include?(k) }
132
+ end
133
+ end
134
+ end
@@ -0,0 +1,50 @@
1
+ # WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema
2
+
3
+ module BaseCRM
4
+ class PipelinesService
5
+ def initialize(client)
6
+ @client = client
7
+ end
8
+
9
+ # Retrieve all pipelines
10
+ #
11
+ # get '/pipelines'
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 pipelines
20
+ #
21
+ # get '/pipelines'
22
+ #
23
+ # Returns all pipelines available to the user, according to the parameters provided
24
+ #
25
+ # @param options [Hash] Search options
26
+ # @option options [String] :ids Comma-separated list of pipeline IDs to be returned in a request.
27
+ # @option options [String] :name Name of the pipeline to search for. This parameter is used in a strict sense. Unsupported for now.
28
+ # @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.
29
+ # @option options [Integer] :per_page (25) The number of records to be returned per page. The default limit is *25* and the maximum number that can be returned is *100*.
30
+ # @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.
31
+ # @return [Array<Pipeline>] The list of Pipelines for the first page, unless otherwise specified.
32
+ def where(options = {})
33
+ _, _, root = @client.get("/pipelines", options)
34
+
35
+ root[:items].map{ |item| Pipeline.new(item[:data]) }
36
+ end
37
+
38
+
39
+ private
40
+ def validate_type!(pipeline)
41
+ raise TypeError unless pipeline.is_a?(Pipeline) || pipeline.is_a?(Hash)
42
+ end
43
+
44
+ def extract_params!(pipeline, *args)
45
+ params = pipeline.to_h.select{ |k, _| args.include?(k) }
46
+ raise ArgumentError, "one of required attributes is missing. Expected: #{args.join(',')}" if params.count != args.length
47
+ params
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,133 @@
1
+ # WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema
2
+
3
+ module BaseCRM
4
+ class SourcesService
5
+ OPTS_KEYS_TO_PERSIST = Set[:name]
6
+
7
+ def initialize(client)
8
+ @client = client
9
+ end
10
+
11
+ # Retrieve all sources
12
+ #
13
+ # get '/sources'
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 sources
22
+ #
23
+ # get '/sources'
24
+ #
25
+ # Returns all deal sources available to the user according to the parameters provided
26
+ #
27
+ # @param options [Hash] Search options
28
+ # @option options [String] :ids Comma-separated list of deal source IDs to be returned in a request.
29
+ # @option options [String] :name Name of the source to search for. 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] :sort_by (id: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=name:desc`.
33
+ # @return [Array<Source>] The list of Sources for the first page, unless otherwise specified.
34
+ def where(options = {})
35
+ _, _, root = @client.get("/sources", options)
36
+
37
+ root[:items].map{ |item| Source.new(item[:data]) }
38
+ end
39
+
40
+
41
+ # Create a source
42
+ #
43
+ # post '/sources'
44
+ #
45
+ # Creates a new source
46
+ # <figure class="notice">
47
+ # Source's name **must** be unique
48
+ # </figure>
49
+ #
50
+ # @param source [Source, Hash] Either object of the Source type or Hash. This object's attributes describe the object to be created.
51
+ # @return [Source] The resulting object represting created resource.
52
+ def create(source)
53
+ validate_type!(source)
54
+
55
+ attributes = sanitize(source)
56
+ _, _, root = @client.post("/sources", attributes)
57
+
58
+ Source.new(root[:data])
59
+ end
60
+
61
+
62
+ # Retrieve a single source
63
+ #
64
+ # get '/sources/{id}'
65
+ #
66
+ # Returns a single source available to the user by the provided id
67
+ # If a source with the supplied unique identifier does not exist it returns an error
68
+ #
69
+ # @param id [Integer] Unique identifier of a Source
70
+ # @return [Source] Searched resource object.
71
+ def find(id)
72
+ _, _, root = @client.get("/sources/#{id}")
73
+
74
+ Source.new(root[:data])
75
+ end
76
+
77
+
78
+ # Update a source
79
+ #
80
+ # put '/sources/{id}'
81
+ #
82
+ # Updates source information
83
+ # If the specified source does not exist, the request will return an error
84
+ # <figure class="notice">
85
+ # If you want to update a source, you **must** make sure source's name is unique
86
+ # </figure>
87
+ #
88
+ # @param source [Source, Hash] Either object of the Source type or Hash. This object's attributes describe the object to be updated.
89
+ # @return [Source] The resulting object represting updated resource.
90
+ def update(source)
91
+ validate_type!(source)
92
+ params = extract_params!(source, :id)
93
+ id = params[:id]
94
+
95
+ attributes = sanitize(source)
96
+ _, _, root = @client.put("/sources/#{id}", attributes)
97
+
98
+ Source.new(root[:data])
99
+ end
100
+
101
+
102
+ # Delete a source
103
+ #
104
+ # delete '/sources/{id}'
105
+ #
106
+ # Delete an existing source
107
+ # If the specified source does not exist, the request will return an error
108
+ # This operation cannot be undone
109
+ #
110
+ # @param id [Integer] Unique identifier of a Source
111
+ # @return [Boolean] Status of the operation.
112
+ def destroy(id)
113
+ status, _, _ = @client.delete("/sources/#{id}")
114
+ status == 204
115
+ end
116
+
117
+
118
+ private
119
+ def validate_type!(source)
120
+ raise TypeError unless source.is_a?(Source) || source.is_a?(Hash)
121
+ end
122
+
123
+ def extract_params!(source, *args)
124
+ params = source.to_h.select{ |k, _| args.include?(k) }
125
+ raise ArgumentError, "one of required attributes is missing. Expected: #{args.join(',')}" if params.count != args.length
126
+ params
127
+ end
128
+
129
+ def sanitize(source)
130
+ source.to_h.select { |k, _| OPTS_KEYS_TO_PERSIST.include?(k) }
131
+ end
132
+ end
133
+ end