|
| 1 | +# WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema |
| 2 | + |
| 3 | +module BaseCRM |
| 4 | + class TextMessagesService |
| 5 | + def initialize(client) |
| 6 | + @client = client |
| 7 | + end |
| 8 | + |
| 9 | + # Retrieve text messages |
| 10 | + # |
| 11 | + # get '/text_messages' |
| 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 text messages |
| 20 | + # |
| 21 | + # get '/text_messages' |
| 22 | + # |
| 23 | + # Returns Text Messages, according to the parameters provided |
| 24 | + # |
| 25 | + # @param options [Hash] Search options |
| 26 | + # @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. |
| 27 | + # @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*. |
| 28 | + # @option options [String] :ids Comma-separated list of text message IDs to be returned in request. |
| 29 | + # @option options [Integer] :resource_id Unique identifier of a resource the text message is attached to. Requires also resource_type to be specified. |
| 30 | + # @option options [String] :resource_type Name of a resource type the text message is attached to. Requires also resource_id to be specified. |
| 31 | + # @option options [String] :sort_by (id:desc) Comma-separated list of fields to sort by. The sort criteria is applied in the order specified. The **default** ordering is **descending**. If you want to change the sort ordering to ascending, append `:asc` to the field e.g. `sort_by=id:asc` |
| 32 | + # @return [Array<TextMessage>] The list of TextMessages for the first page, unless otherwise specified. |
| 33 | + def where(options = {}) |
| 34 | + _, _, root = @client.get("/text_messages", options) |
| 35 | + |
| 36 | + root[:items].map{ |item| TextMessage.new(item[:data]) } |
| 37 | + end |
| 38 | + |
| 39 | + |
| 40 | + # Retrieve a single text message |
| 41 | + # |
| 42 | + # get '/text_messages/{id}' |
| 43 | + # |
| 44 | + # Returns a single text message according to the unique ID provided |
| 45 | + # If the specified user does not exist, this query returns an error |
| 46 | + # |
| 47 | + # @param id [Integer] Unique identifier of a TextMessage |
| 48 | + # @return [TextMessage] Searched resource object. |
| 49 | + def find(id) |
| 50 | + _, _, root = @client.get("/text_messages/#{id}") |
| 51 | + |
| 52 | + TextMessage.new(root[:data]) |
| 53 | + end |
| 54 | + |
| 55 | + |
| 56 | + private |
| 57 | + def validate_type!(text_message) |
| 58 | + raise TypeError unless text_message.is_a?(TextMessage) || text_message.is_a?(Hash) |
| 59 | + end |
| 60 | + |
| 61 | + def extract_params!(text_message, *args) |
| 62 | + params = text_message.to_h.select{ |k, _| args.include?(k) } |
| 63 | + raise ArgumentError, "one of required attributes is missing. Expected: #{args.join(',')}" if params.count != args.length |
| 64 | + params |
| 65 | + end |
| 66 | + end |
| 67 | +end |
0 commit comments