├── .github └── workflows │ └── gempush.yml ├── .gitignore ├── .rspec ├── CHANGELOG.md ├── Gemfile ├── LICENSE ├── README.md ├── VERSION ├── basecrm.gemspec ├── lib ├── basecrm.rb └── basecrm │ ├── configuration.rb │ ├── envelope.rb │ ├── errors.rb │ ├── http_client.rb │ ├── middlewares │ ├── oauth_bearer_token.rb │ └── raise_error.rb │ ├── model.rb │ ├── models │ ├── account.rb │ ├── address.rb │ ├── associated_contact.rb │ ├── call.rb │ ├── call_outcome.rb │ ├── contact.rb │ ├── deal.rb │ ├── deal_source.rb │ ├── deal_unqualified_reason.rb │ ├── lead.rb │ ├── lead_source.rb │ ├── lead_unqualified_reason.rb │ ├── line_item.rb │ ├── loss_reason.rb │ ├── meta.rb │ ├── note.rb │ ├── order.rb │ ├── pipeline.rb │ ├── price.rb │ ├── product.rb │ ├── source.rb │ ├── stage.rb │ ├── sync_meta.rb │ ├── sync_queue.rb │ ├── sync_session.rb │ ├── tag.rb │ ├── task.rb │ ├── text_message.rb │ ├── user.rb │ ├── visit.rb │ └── visit_outcome.rb │ ├── paginated_resource.rb │ ├── services │ ├── accounts_service.rb │ ├── associated_contacts_service.rb │ ├── call_outcomes_service.rb │ ├── calls_service.rb │ ├── contacts_service.rb │ ├── deal_sources_service.rb │ ├── deal_unqualified_reasons_service.rb │ ├── deals_service.rb │ ├── lead_sources_service.rb │ ├── lead_unqualified_reasons_service.rb │ ├── leads_service.rb │ ├── line_items_service.rb │ ├── loss_reasons_service.rb │ ├── notes_service.rb │ ├── orders_service.rb │ ├── pipelines_service.rb │ ├── products_service.rb │ ├── sources_service.rb │ ├── stages_service.rb │ ├── sync_service.rb │ ├── tags_service.rb │ ├── tasks_service.rb │ ├── text_messages_service.rb │ ├── users_service.rb │ ├── visit_outcomes_service.rb │ └── visits_service.rb │ ├── sync.rb │ ├── utils │ └── coercion.rb │ └── version.rb └── spec ├── basecrm └── sync_spec.rb ├── factories ├── associated_contact.rb ├── call.rb ├── contact.rb ├── deal.rb ├── deal_source.rb ├── deal_unqualified_reason.rb ├── lead.rb ├── lead_source.rb ├── lead_unqualified_reason.rb ├── line_item.rb ├── loss_reason.rb ├── note.rb ├── order.rb ├── product.rb ├── source.rb ├── tag.rb ├── task.rb └── text_message.rb ├── http_client_spec.rb ├── middlewares └── raise_error_spec.rb ├── models └── sync_meta_spec.rb ├── services ├── accounts_service_spec.rb ├── associated_contacts_service_spec.rb ├── call_outcomes_service_spec.rb ├── calls_service_spec.rb ├── contacts_service_spec.rb ├── deal_sources_service_spec.rb ├── deal_unqualified_reasons_service_spec.rb ├── deals_service_spec.rb ├── lead_sources_service_spec.rb ├── lead_unqualified_reasons_service_spec.rb ├── leads_service_spec.rb ├── line_items_service_spec.rb ├── loss_reasons_service_spec.rb ├── notes_service_spec.rb ├── orders_service_spec.rb ├── pipelines_service_spec.rb ├── products_service_spec.rb ├── sources_service_spec.rb ├── stages_service_spec.rb ├── sync_service_spec.rb ├── tags_service_spec.rb ├── tasks_service_spec.rb ├── text_messages_service_spec.rb ├── users_service_spec.rb ├── visit_outcomes_service_spec.rb └── visits_service_spec.rb ├── spec_helper.rb ├── support └── client_helpers.rb └── utils ├── coercion.rb └── coercion_spec.rb /.github/workflows/gempush.yml: -------------------------------------------------------------------------------- 1 | name: Ruby Gem 2 | 3 | on: 4 | push: 5 | tags: v* 6 | 7 | jobs: 8 | build: 9 | name: Build + Publish 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - uses: zendesk/checkout@v2 14 | - name: Set up Ruby 2.6 15 | uses: zendesk/setup-ruby@v1 16 | with: 17 | ruby-version: 2.6 18 | 19 | - name: Publish to RubyGems 20 | run: | 21 | mkdir -p $HOME/.gem 22 | touch $HOME/.gem/credentials 23 | chmod 0600 $HOME/.gem/credentials 24 | printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials 25 | gem build *.gemspec 26 | gem push *.gem 27 | env: 28 | GEM_HOST_API_KEY: ${{secrets.RUBYGEMS_AUTH_TOKEN}} 29 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | *.rbc 3 | .bundle 4 | .config 5 | .yardoc 6 | Gemfile.lock 7 | InstalledFiles 8 | _yardoc 9 | coverage 10 | doc/ 11 | lib/bundler/man 12 | pkg 13 | rdoc 14 | spec/reports 15 | test/tmp 16 | test/version_tmp 17 | tmp 18 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --colour 2 | --format Fuubar 3 | --order random 4 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## CHANGELOG 2 | v2.0.0 (2021-10-26) 3 | **Features and Improvements** 4 | * Faraday updated to version > 1.0 5 | * Optional parameters `max_retry` and `retry_statuses` to specify no. of retries on failed request and statuses to retry. 6 | 7 | v1.3.10 (2021-06-28) 8 | **Features and Improvements** 9 | * Added possibility to set deal's 'added_on' attribute 10 | 11 | v1.3.9 (2021-03-30) 12 | **Features and Improvements** 13 | 14 | * Fixed issue where `unqualified_reason_id` param for deals could not be updated 15 | 16 | v1.3.8 (2019-05-11) 17 | **Features and Improvements** 18 | 19 | * Update github url references to new Zendesk organisation 20 | 21 | v1.3.7 (2019-04-22) 22 | **Features and Improvements** 23 | 24 | * Update gemspec license and authors 25 | 26 | v1.3.6 (2019-02-18) 27 | **Features and Improvements** 28 | 29 | * Update Contact model documentation 30 | * Replace deprecated `BigDecimal.new()` with `BigDecimal()` 31 | * Replace deprecated `FactoryGirl` gem with `FactoryBot` gem 32 | 33 | v1.3.5 (2018-10-09) 34 | **Features and Improvements** 35 | 36 | * Added new models support: TextMessage, Visit and VisitOutcome 37 | 38 | v1.3.4 (2018-07-04) 39 | **Features and Improvements** 40 | 41 | * Added new models support: Call, CallOutcome 42 | 43 | v1.3.3 (2018-06-05) 44 | **Features and Improvements** 45 | 46 | * Added new models support: LeadUnqualifiedReason, DealUnqualifiedReason 47 | 48 | v1.3.2 (2018-01-11) 49 | **Features and Improvements** 50 | 51 | * Fixed undefined method exception on error handling [issue #54](https://github.com/zendesk/basecrm-ruby/issues/54) 52 | 53 | v1.3.1 (2017-12-08) 54 | **Features and Improvements** 55 | 56 | * Fixed issue where could not update deal without passing value 57 | 58 | v1.3.0 (2017-10-19) 59 | **Features and Improvements** 60 | 61 | * Added new models support: LeadSource, DealSource, Product, Order, LineItem 62 | * Deal model update, added estimated_close_date and customized_win_likelihood 63 | 64 | v1.2.3 (2017-10-02) 65 | **Features and Improvements** 66 | 67 | * Missing source_id in Leads model 68 | * Relax upper version boundary for JSON gem dependency 69 | 70 | v1.2.2 (2017-04-03) 71 | **Features and Improvements** 72 | 73 | * Missing last_stage_change_at in Deals model [#45](https://github.com/zendesk/basecrm-ruby/pull/45) 74 | 75 | v1.2.1 (2016-11-18) 76 | 77 | **Features and Improvements** 78 | 79 | * Fix deal creation with hash as argument [#39](https://github.com/zendesk/basecrm-ruby/pull/39) 80 | 81 | ## v1.2.0 (2016-07-24) 82 | 83 | **Features and Improvements** 84 | 85 | * Decimal deal values support [#34](https://github.com/zendesk/basecrm-ruby/pull/34) 86 | * Deal value is now a BigDecimal [#34](https://github.com/zendesk/basecrm-ruby/pull/34) 87 | 88 | ### v1.1.3 (2015-06-17) 89 | 90 | **Features and Improvements** 91 | 92 | * Compatibility with Ruby 2.0.0+ 93 | 94 | ### v1.1.2 (2015-06-17) 95 | 96 | **Features and Improments** 97 | 98 | * `BaseCRM::HttpClient` prints response payload in debug mode. 99 | * `BaseCRM::SyncService#fetch` method return `nil` value if there is nothing more to synchronize. Previously it returned an empty array. This change fixes an issue where the sync service can return an empty array as a valid response. 100 | 101 | ### v1.1.1 (2015-06-10) 102 | 103 | **Features and Improvements** 104 | 105 | * Sync API support 106 | * better handling of unexpected entity types 107 | * `BaseCRM::SyncService#fetch` method returns `BaseCRM::Meta`instead of `BaseCRM::SyncMeta`. 108 | This gives you additional information such as type. 109 | * High-level `BaseCRM::Sync` wrapper expects either `meta.sync.ack` or `meta.sync.nack` to be called. 110 | 111 | ### v1.1.0 (2015-05-29) 112 | 113 | **Features and Improvements** 114 | 115 | * Sync API support 116 | * New `BaseCRM::SyncService` 117 | * High-level `BaseCRM::Sync` wrapper 118 | 119 | ### v1.0.0 (2015-04-17) 120 | 121 | * Birth! 122 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | # A sample Gemfile 2 | source "https://rubygems.org" 3 | 4 | gemspec 5 | -------------------------------------------------------------------------------- /VERSION: -------------------------------------------------------------------------------- 1 | 2.0.0 2 | -------------------------------------------------------------------------------- /basecrm.gemspec: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | 3 | lib = File.expand_path('../lib', __FILE__) 4 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 5 | require 'basecrm/version' 6 | 7 | Gem::Specification.new do |spec| 8 | spec.name = "basecrm" 9 | spec.version = BaseCRM::VERSION 10 | spec.summary = "Zendesk Sell Official API V2 library client for ruby" 11 | spec.description = "Zendesk Sell Official API V2 library client for ruby" 12 | 13 | spec.authors = ["Zendesk"] 14 | spec.email = ["opensource@zendesk.com"] 15 | spec.homepage = "https://github.com/zendesk/basecrm-ruby" 16 | spec.license = "Apache License Version 2.0" 17 | 18 | spec.require_paths = ["lib"] 19 | 20 | spec.files = Dir["README.md", "LICENSE", "lib/**/*"] 21 | spec.test_files = Dir["spec/**/*"] 22 | 23 | spec.add_dependency "faraday", "~> 1.0" 24 | spec.add_dependency "json", "~> 2.0" 25 | 26 | spec.add_development_dependency "rspec", "~> 3.2" 27 | spec.add_development_dependency "rspec-collection_matchers", "~> 1.1" 28 | spec.add_development_dependency "fuubar", "~> 2.0" 29 | spec.add_development_dependency "factory_bot", "~> 4.11" 30 | spec.add_development_dependency "faker", "~> 1.4" 31 | end 32 | -------------------------------------------------------------------------------- /lib/basecrm/configuration.rb: -------------------------------------------------------------------------------- 1 | require 'uri' 2 | 3 | module BaseCRM 4 | class Configuration 5 | attr_reader :access_token 6 | attr_reader :base_url 7 | attr_reader :user_agent 8 | attr_reader :timeout 9 | attr_reader :verify_ssl 10 | attr_reader :max_retry 11 | attr_reader :retry_statuses 12 | 13 | attr_reader :logger, :verbose 14 | alias_method :debug?, :verbose 15 | 16 | def initialize(options={}) 17 | @access_token = options[:access_token] 18 | @base_url = options[:base_url] || "https://api.getbase.com" 19 | @user_agent = options[:user_agent] || "BaseCRM/v2 Ruby/#{VERSION}" 20 | @logger = options[:logger] 21 | @verbose = !!options[:verbose] 22 | @timeout = options[:timeout] || 30 23 | @verify_ssl = options.fetch(:verify_ssl, true) 24 | @max_retry = options[:max_retry] 25 | @retry_statuses = options[:retry_statuses] 26 | end 27 | 28 | def validate! 29 | unless @access_token 30 | raise ConfigurationError.new('No access token provided. '\ 31 | 'Set your access token during client initialization using: '\ 32 | '"Base::Client.new(access_token: )".') 33 | end 34 | 35 | if @access_token =~ /\s/ 36 | raise ConfigurationError.new('Provided access token is invalid '\ 37 | 'as it contains disallowed characters. '\ 38 | 'Please double-check your access token.') 39 | end 40 | 41 | if @access_token.length != 64 42 | raise ConfigurationError.new('Provided access token is invalid '\ 43 | 'as it has invalid length. '\ 44 | 'Please double-check your access token.') 45 | 46 | end 47 | 48 | unless /\A#{URI.regexp(%w(http https)).to_s}\z/.match(@base_url) 49 | raise ConfigurationError.new('Provided base url is invalid '\ 50 | 'as it is not a valid URI. '\ 51 | 'Please make sure it includes the scheme part, both http and https are accepted, '\ 52 | 'and the hierarchical part.') 53 | end 54 | 55 | end 56 | 57 | def inspect 58 | instance_variables.map { |ivar| 59 | "#{ivar}=#{self.instance_variable_get(ivar)}" 60 | }.join("\n") 61 | end 62 | end 63 | end 64 | -------------------------------------------------------------------------------- /lib/basecrm/envelope.rb: -------------------------------------------------------------------------------- 1 | module BaseCRM 2 | module Envelope 3 | def self.wrap(data) 4 | JSON.dump({data: data}) 5 | end 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /lib/basecrm/errors.rb: -------------------------------------------------------------------------------- 1 | module BaseCRM 2 | class ConnectionError < StandardError 3 | end 4 | 5 | class ConfigurationError < StandardError 6 | end 7 | 8 | class BaseError < StandardError 9 | attr_reader :code, :message, :details 10 | 11 | def initialize(error) 12 | @data = error[:error] 13 | @meta = error[:meta] 14 | 15 | @code = @data[:code] 16 | @message = @data[:message] 17 | @details = @data[:details] 18 | end 19 | 20 | def to_s 21 | "code=#{@code} message=#{message} details=#{details}" 22 | end 23 | end 24 | 25 | class RequestError < BaseError 26 | end 27 | 28 | class ResourceError < BaseError 29 | attr_reader :resource, :field 30 | 31 | def initialize(error) 32 | super 33 | 34 | @resource = @data[:resource] 35 | @field = @data[:field] 36 | end 37 | 38 | def to_s 39 | super + " resource=#{@resource} field=#{@field}" 40 | end 41 | end 42 | 43 | class ServerError < BaseError 44 | end 45 | 46 | class ErrorsCollection < StandardError 47 | attr_reader :errors 48 | 49 | attr_reader :http_status, :logref 50 | alias_method :request_id, :logref 51 | 52 | 53 | def initialize(errors, meta) 54 | @errors = errors 55 | 56 | @http_status = meta[:http_status] 57 | @logref = meta[:logref] 58 | end 59 | 60 | def to_s 61 | status = "[#{@logref}] http_status=#{@http_status}\n" 62 | status + @errors.map(&:to_s).join("\n") 63 | end 64 | end 65 | end 66 | -------------------------------------------------------------------------------- /lib/basecrm/http_client.rb: -------------------------------------------------------------------------------- 1 | require_relative 'middlewares/oauth_bearer_token' 2 | require_relative 'middlewares/raise_error' 3 | 4 | module BaseCRM 5 | class HttpClient 6 | 7 | attr_reader :headers 8 | 9 | def initialize(config) 10 | @config = config 11 | 12 | @headers = { 13 | 'User-Agent' => config.user_agent, 14 | 'Accept' => 'application/json' 15 | } 16 | 17 | @api_version = "/v2" 18 | 19 | options = { 20 | # timeout: config.timeout 21 | } 22 | options[:ssl] = { verify: false } unless config.verify_ssl 23 | 24 | @client = Faraday.new(config.base_url, options) do |faraday| 25 | faraday.request :retry, retry_options 26 | faraday.use BaseCRM::Middlewares::OAuthBearerToken, config.access_token 27 | faraday.use BaseCRM::Middlewares::RaiseError 28 | faraday.response :logger, config.logger if config.debug? 29 | 30 | faraday.adapter Faraday.default_adapter 31 | end 32 | end 33 | 34 | def get(path, params={}, headers={}) 35 | request(:get, path, params, headers) 36 | end 37 | 38 | def post(path, body={}, headers={}) 39 | request(:post, path, body, headers) 40 | end 41 | 42 | def put(path, body={}, headers={}) 43 | request(:put, path, body, headers) 44 | end 45 | 46 | def delete(path, params={}, headers={}) 47 | request(:delete, path, params) 48 | end 49 | 50 | def request(method, path, data={}, headers={}) 51 | options = { 52 | headers: @headers.merge(headers.to_h) 53 | } 54 | 55 | case method.to_s.downcase.to_sym 56 | when :get, :head, :delete 57 | options[:query] = encode_params(data) unless data.empty? 58 | else 59 | unless data.empty? 60 | options[:headers]['Content-Type'] = 'application/json' 61 | options[:body] = Envelope.wrap(data) 62 | end 63 | end 64 | 65 | path = "#{@api_version}#{path}" 66 | 67 | res = instance_eval <<-RUBY, __FILE__, __LINE__ + 1 68 | @client.#{method}(path) do |req| 69 | req.body = options[:body] if options[:body] 70 | req.headers.update(options[:headers]) 71 | req.params.update(options[:query]) if options[:query] 72 | end 73 | RUBY 74 | 75 | body = extract_body(res) 76 | @config.logger.debug body if @config.debug? && body && @config.logger 77 | [res.status, res.headers, body] 78 | rescue Faraday::ConnectionFailed => e 79 | raise ConnectionError, e.message 80 | end 81 | 82 | private 83 | def encode_params(params) 84 | Hash[params.map { |k, v| 85 | v.is_a?(Array) ? [k, v.join(',')] : [k, v] 86 | }] 87 | end 88 | 89 | def extract_body(res) 90 | content_type = res.headers['Content-Type'] 91 | content_type && content_type.include?('json') ? JSON.parse(res.body, symbolize_names: true) : res.body 92 | end 93 | 94 | def retry_options 95 | retry_options = {} 96 | retry_options[:max] = @config.max_retry if @config.max_retry 97 | retry_options[:retry_statuses] = @config.retry_statuses if @config.retry_statuses 98 | retry_options 99 | end 100 | end 101 | end 102 | -------------------------------------------------------------------------------- /lib/basecrm/middlewares/oauth_bearer_token.rb: -------------------------------------------------------------------------------- 1 | module BaseCRM 2 | module Middlewares 3 | class OAuthBearerToken < Faraday::Middleware 4 | 5 | def initialize(app, access_token) 6 | super app 7 | @access_token = access_token 8 | end 9 | 10 | 11 | def call(env) 12 | env[:request_headers]["Authorization"] = "Bearer #{@access_token}" 13 | @app.call(env) 14 | end 15 | 16 | end 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /lib/basecrm/middlewares/raise_error.rb: -------------------------------------------------------------------------------- 1 | module BaseCRM 2 | module Middlewares 3 | class RaiseError < Faraday::Response::Middleware 4 | 5 | def on_complete(env) 6 | status = env[:status] 7 | return if (200...300).member?(status) 8 | 9 | content_type = env[:response_headers]['content-type'] 10 | 11 | 12 | error_klass = case status 13 | when 422 then BaseCRM::ResourceError 14 | when 400...500 then BaseCRM::RequestError 15 | when 500...600 then BaseCRM::ServerError 16 | end 17 | 18 | if !content_type.nil? && content_type.include?('json') 19 | raise errors_collection(env, error_klass) 20 | else 21 | error = {:error=>{:code=>status, :message=>"Unknown error occurred."}, :meta=>{}} 22 | raise error_klass.new(error) 23 | end 24 | end 25 | 26 | def errors_collection(env, error_klass) 27 | envelope = JSON.parse(env[:body], symbolize_names: true) 28 | errors = envelope[:errors] 29 | ErrorsCollection.new(errors.map { |e| error_klass.new(e) }, envelope[:meta]) 30 | end 31 | end 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /lib/basecrm/model.rb: -------------------------------------------------------------------------------- 1 | require 'ostruct' 2 | 3 | module BaseCRM 4 | class Model < OpenStruct 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/basecrm/models/account.rb: -------------------------------------------------------------------------------- 1 | # WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | module BaseCRM 4 | class Account < Model 5 | # @!attribute [r] created_at 6 | # @return [DateTime] Date and time of the account's creation in UTC (ISO8601 format). 7 | # attr_reader :created_at 8 | # @!attribute [r] id 9 | # @return [Integer] Unique identifier of the account. 10 | # attr_reader :id 11 | # @!attribute [r] updated_at 12 | # @return [DateTime] Date and time of the last update in UTC (ISO8601 format). 13 | # attr_reader :updated_at 14 | 15 | # @!attribute [rw] currency 16 | # @return [String] Currency of the account as the 3-character currency code in ISO4217 format. 17 | # attr_accessor :currency 18 | # @!attribute [rw] name 19 | # @return [String] Full name of the account. 20 | # attr_accessor :name 21 | # @!attribute [rw] phone 22 | # @return [String] Contact phone number of the account. 23 | # attr_accessor :phone 24 | # @!attribute [rw] time_format 25 | # @return [String] Time format used for the account. Either 12-hour clock `12H` or 24-hour clock `24H`. 26 | # attr_accessor :time_format 27 | # @!attribute [rw] timezone 28 | # @return [String] Timezone of the account as the offset from Coordinated Universal Time (UTC) in the format `UTC(+|-)[hh]:[mm]`. 29 | # attr_accessor :timezone 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /lib/basecrm/models/address.rb: -------------------------------------------------------------------------------- 1 | # WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | module BaseCRM 4 | class Address < Model 5 | 6 | # @!attribute [rw] city 7 | # @return [String] City name. 8 | # attr_accessor :city 9 | # @!attribute [rw] country 10 | # @return [String] Country name. 11 | # attr_accessor :country 12 | # @!attribute [rw] line1 13 | # @return [String] Line 1 of the address e.g. number, street, suite, apt #, etc. 14 | # attr_accessor :line1 15 | # @!attribute [rw] postal_code 16 | # @return [String] Zip code or equivalent. 17 | # attr_accessor :postal_code 18 | # @!attribute [rw] state 19 | # @return [String] State name. 20 | # attr_accessor :state 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /lib/basecrm/models/associated_contact.rb: -------------------------------------------------------------------------------- 1 | # WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | module BaseCRM 4 | class AssociatedContact < Model 5 | # @!attribute [r] created_at 6 | # @return [DateTime] Date and time that the associated contact was created in UTC (ISO8601 format). 7 | # attr_reader :created_at 8 | # @!attribute [r] updated_at 9 | # @return [DateTime] Date and time of the last update on the associated contact in UTC (ISO8601 format). 10 | # attr_reader :updated_at 11 | 12 | # @!attribute [rw] contact_id 13 | # @return [Integer] Unique identifier of the contact to be associated with the deal. 14 | # attr_accessor :contact_id 15 | # @!attribute [rw] role 16 | # @return [String] Role name. 17 | # attr_accessor :role 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /lib/basecrm/models/call.rb: -------------------------------------------------------------------------------- 1 | # WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | module BaseCRM 4 | class Call < Model 5 | # @!attribute [r] id 6 | # @return [Integer] Unique identifier of the call. 7 | # attr_reader :id 8 | # @!attribute [r] upated_at 9 | # @return [DateTime] Date and time of the last update in UTC (ISO8601 format). 10 | # attr_reader :upated_at 11 | 12 | # @!attribute [rw] associated_deal_ids 13 | # @return [Array] An array of ids of deals associated to the call. 14 | # attr_accessor :associated_deal_ids 15 | # @!attribute [rw] duration 16 | # @return [Integer] Duration of the call in seconds. 17 | # attr_accessor :duration 18 | # @!attribute [rw] external_id 19 | # @return [String] Unique identifier of a call from an external system. 20 | # attr_accessor :external_id 21 | # @!attribute [rw] incoming 22 | # @return [Boolean] Phone number of the person with which the call was made. 23 | # attr_accessor :incoming 24 | # @!attribute [rw] made_at 25 | # @return [DateTime] Date and time of when the call was made (started) in UTC (ISO8601 format). 26 | # attr_accessor :made_at 27 | # @!attribute [rw] missed 28 | # @return [Boolean] Indicator of whether the call was missed (not answered) by the user or not. 29 | # attr_accessor :missed 30 | # @!attribute [rw] outcome_id 31 | # @return [Integer] Unique identifier of Call Outcome assigned to the call. 32 | # attr_accessor :outcome_id 33 | # @!attribute [rw] phone_number 34 | # @return [String] Indicator of whether the call was incoming or not. 35 | # attr_accessor :phone_number 36 | # @!attribute [rw] recording_url 37 | # @return [String] URL pointing to call recording. 38 | # attr_accessor :recording_url 39 | # @!attribute [rw] resource_id 40 | # @return [Integer] Unique identifier of the resource the call is attached to. 41 | # attr_accessor :resource_id 42 | # @!attribute [rw] resource_type 43 | # @return [String] Name of the resource type the call is attached to. 44 | # attr_accessor :resource_type 45 | # @!attribute [rw] summary 46 | # @return [String] Content of the note about this call. 47 | # attr_accessor :summary 48 | # @!attribute [rw] user_id 49 | # @return [Integer] Unique identifier of the user who performed the call. 50 | # attr_accessor :user_id 51 | end 52 | end 53 | -------------------------------------------------------------------------------- /lib/basecrm/models/call_outcome.rb: -------------------------------------------------------------------------------- 1 | # WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | module BaseCRM 4 | class CallOutcome < Model 5 | # @!attribute [r] created_at 6 | # @return [DateTime] Date and time of when the call outcome was created in UTC (ISO8601 format). 7 | # attr_reader :created_at 8 | # @!attribute [r] creator_id 9 | # @return [Integer] Unique identifier of the user who created the call outcome. 10 | # attr_reader :creator_id 11 | # @!attribute [r] id 12 | # @return [Integer] Unique identifier of the call outcome. 13 | # attr_reader :id 14 | # @!attribute [r] name 15 | # @return [String] Name of the call outcome. 16 | # attr_reader :name 17 | # @!attribute [r] updated_at 18 | # @return [DateTime] Date and time of the last update in UTC (ISO8601 format). 19 | # attr_reader :updated_at 20 | 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /lib/basecrm/models/contact.rb: -------------------------------------------------------------------------------- 1 | # WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | module BaseCRM 4 | class Contact < Model 5 | # @!attribute [r] created_at 6 | # @return [DateTime] Date and time that the record was created in UTC ISO8601 format. 7 | # attr_reader :created_at 8 | # @!attribute [r] creator_id 9 | # @return [Integer] The unique identifier of the user the contact was created by. 10 | # attr_reader :creator_id 11 | # @!attribute [r] id 12 | # @return [Integer] The unique identifier of the contact. 13 | # attr_reader :id 14 | # @!attribute [r] updated_at 15 | # @return [DateTime] Date and time of the record's last update in UTC ISO8601 format. 16 | # attr_reader :updated_at 17 | 18 | # @!attribute [rw] address 19 | # @return [Address] 20 | # attr_accessor :address 21 | # @!attribute [rw] contact_id 22 | # @return [Integer] The unique identifier of the organization the contact belongs to. The field will be set only if the contact is an individual. 23 | # attr_accessor :contact_id 24 | # @!attribute [rw] custom_fields 25 | # @return [Hash] Custom fields are a key-value pair attached to a contact. See more at [Custom Fields](/docs/rest/articles/requests#custom_fields). Note! You need to set Filterable on from Settings -> Contacts to be able to search by custom fields 26 | # attr_accessor :custom_fields 27 | # @!attribute [rw] customer_status 28 | # @return [String] The customer status of the contact. 29 | # attr_accessor :customer_status 30 | # @!attribute [rw] description 31 | # @return [String] The contact's description. 32 | # attr_accessor :description 33 | # @!attribute [rw] email 34 | # @return [String] The contact's email address. 35 | # attr_accessor :email 36 | # @!attribute [rw] facebook 37 | # @return [String] The contact's Facebook nickname. 38 | # attr_accessor :facebook 39 | # @!attribute [rw] fax 40 | # @return [String] The contact's fax number. 41 | # attr_accessor :fax 42 | # @!attribute [rw] first_name 43 | # @return [String] First name of the contact. 44 | # attr_accessor :first_name 45 | # @!attribute [rw] industry 46 | # @return [String] The contact's industry. 47 | # attr_accessor :industry 48 | # @!attribute [rw] is_organization 49 | # @return [Boolean] Indicator of whether or not this contact refers to an organization or an individual. This value can be set **only** during creation and **cannot** be changed later. The default value is `false`. 50 | # attr_accessor :is_organization 51 | # @!attribute [rw] last_name 52 | # @return [String] Last name of the contact. Required only if the contact is an individual. 53 | # attr_accessor :last_name 54 | # @!attribute [rw] linkedin 55 | # @return [String] The contact's Linkedin nickname. 56 | # attr_accessor :linkedin 57 | # @!attribute [rw] mobile 58 | # @return [String] The contact's mobile phone number. 59 | # attr_accessor :mobile 60 | # @!attribute [rw] name 61 | # @return [String] Name of the contact. Required only if the contact is an organization. 62 | # attr_accessor :name 63 | # @!attribute [rw] owner_id 64 | # @return [Integer] The unique identifier of the user the contact is currently assigned to. 65 | # attr_accessor :owner_id 66 | # @!attribute [rw] phone 67 | # @return [String] The contact's phone number. 68 | # attr_accessor :phone 69 | # @!attribute [rw] prospect_status 70 | # @return [String] The prospect status of the contact. 71 | # attr_accessor :prospect_status 72 | # @!attribute [rw] skype 73 | # @return [String] The contact's Skype nickname. 74 | # attr_accessor :skype 75 | # @!attribute [rw] tags 76 | # @return [Array] An array of tags for the contact. See more at [Tags](/docs/rest/articles/requests#tags). 77 | # attr_accessor :tags 78 | # @!attribute [rw] title 79 | # @return [String] The contact's job title. 80 | # attr_accessor :title 81 | # @!attribute [rw] twitter 82 | # @return [String] The contact's Twitter handle. 83 | # attr_accessor :twitter 84 | # @!attribute [rw] website 85 | # @return [String] The contact's website address. 86 | # attr_accessor :website 87 | end 88 | end 89 | -------------------------------------------------------------------------------- /lib/basecrm/models/deal.rb: -------------------------------------------------------------------------------- 1 | # WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | module BaseCRM 4 | class Deal < Model 5 | # @!attribute [r] created_at 6 | # @return [DateTime] Date and time that the deal was created in UTC (ISO8601 format). 7 | # attr_reader :created_at 8 | # @!attribute [r] creator_id 9 | # @return [Integer] Unique identifier of the user who created the deal. 10 | # attr_reader :creator_id 11 | # @!attribute [r] dropbox_email 12 | # @return [String] Dropbox email connected with the deal. 13 | # attr_reader :dropbox_email 14 | # @!attribute [r] id 15 | # @return [Integer] Unique identifier of the deal. 16 | # attr_reader :id 17 | # @!attribute [r] last_stage_change_by_id 18 | # @return [Integer] Unique identifier of the user who moved the deal into the current stage. 19 | # attr_reader :last_stage_change_by_id 20 | # @!attribute [r] organization_id 21 | # @return [Integer] Unique identifier of an organization. 22 | # attr_reader :organization_id 23 | # @!attribute [r] updated_at 24 | # @return [DateTime] Date and time of the last update on the deal in UTC (ISO8601 format). 25 | # attr_reader :updated_at 26 | 27 | # @!attribute [rw] contact_id 28 | # @return [Integer] Unique identifier of a primary contact. 29 | # attr_accessor :contact_id 30 | # @!attribute [rw] currency 31 | # @return [String] Currency of the deal, specified in 3-character currency code (ISO4217) format. 32 | # attr_accessor :currency 33 | # @!attribute [rw] custom_fields 34 | # @return [Hash] Custom fields are key-value data attached to a deal. See more at [Custom Fields](/docs/rest/articles/requests#custom_fields). 35 | # attr_accessor :custom_fields 36 | # @!attribute [rw] customized_win_likelihood 37 | # @return [Integer] User-provided win likelihood with value range 0-100. 38 | # attr_accessor :customized_win_likelihood 39 | # @!attribute [rw] estimated_close_date 40 | # @return [String] Estimated close date of the deal 41 | # attr_accessor :estimated_close_date 42 | # @!attribute [rw] hot 43 | # @return [Boolean] Indicator of whether or not the deal is hot. 44 | # attr_accessor :hot 45 | # @!attribute [rw] last_stage_change_at 46 | # @return [DateTime] Date and time when the deal was moved into the current stage in UTC (ISO8601 format). 47 | # attr_accessor :last_stage_change_at 48 | # @!attribute [rw] loss_reason_id 49 | # @return [Integer] Reason why the deal was lost. 50 | # attr_accessor :loss_reason_id 51 | # @!attribute [rw] name 52 | # @return [String] Name of the deal. 53 | # attr_accessor :name 54 | # @!attribute [rw] owner_id 55 | # @return [Integer] Unique identifier of the user that the deal is assigned to. 56 | # attr_accessor :owner_id 57 | # @!attribute [rw] source_id 58 | # @return [Integer] Unique identifier of the Source. 59 | # attr_accessor :source_id 60 | # @!attribute [rw] stage_id 61 | # @return [Integer] Unique identifier of the deal's current stage in the pipeline. 62 | # attr_accessor :stage_id 63 | # @!attribute [rw] tags 64 | # @return [Array] An array of tags for a deal. See more at [Tags](/docs/rest/articles/requests#tags). 65 | # attr_accessor :tags 66 | # @!attribute [rw] added_on 67 | # @return [DateTime] Date and time when the deal was added in UTC (ISO8601 format). 68 | # attr_accessor :added_on 69 | # @!attribute [rw] value 70 | # @return [BigDecimal] Value of the deal in a currency specified in the `currency` field. 71 | # attr_accessor :value 72 | 73 | def initialize(*args) 74 | super 75 | @table[:value] = BaseCRM::Coercion.to_decimal_value(@table[:value] || 0) 76 | end 77 | end 78 | end 79 | -------------------------------------------------------------------------------- /lib/basecrm/models/deal_source.rb: -------------------------------------------------------------------------------- 1 | # WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | module BaseCRM 4 | class DealSource < Model 5 | # @!attribute [r] created_at 6 | # @return [String] Date and time of creation in UTC (ISO 8601 format). 7 | # attr_reader :created_at 8 | # @!attribute [r] creator_id 9 | # @return [Integer] Unique identifier of the user that created the source. 10 | # attr_reader :creator_id 11 | # @!attribute [r] id 12 | # @return [Integer] Unique identifier of the deal source. 13 | # attr_reader :id 14 | # @!attribute [r] updated_at 15 | # @return [String] Date and time of the last update in UTC (ISO 8601 format). 16 | # attr_reader :updated_at 17 | 18 | # @!attribute [rw] name 19 | # @return [String] Name of the source. 20 | # attr_accessor :name 21 | # @!attribute [rw] resource_type 22 | # @return [String] Type name of the resource the source is attached to. Possible values: deal 23 | # attr_accessor :resource_type 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /lib/basecrm/models/deal_unqualified_reason.rb: -------------------------------------------------------------------------------- 1 | # WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | module BaseCRM 4 | class DealUnqualifiedReason < Model 5 | # @!attribute [r] created_at 6 | # @return [DateTime] Date and time of creation in UTC ISO8601 format. 7 | # attr_reader :created_at 8 | # @!attribute [r] creator_id 9 | # @return [Integer] Unique identifier of the user the deal unqualified reason was created by. 10 | # attr_reader :creator_id 11 | # @!attribute [r] id 12 | # @return [Integer] Unique identifier of the deal unqualified reason. 13 | # attr_reader :id 14 | # @!attribute [r] updated_at 15 | # @return [DateTime] Date and time of the last update in UTC ISO8601 format. 16 | # attr_reader :updated_at 17 | 18 | # @!attribute [rw] name 19 | # @return [String] Human-friendly unqualified reason explanation. 20 | # attr_accessor :name 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /lib/basecrm/models/lead.rb: -------------------------------------------------------------------------------- 1 | # WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | module BaseCRM 4 | class Lead < Model 5 | # @!attribute [r] created_at 6 | # @return [DateTime] Date and time of the creation in UTC (ISO8601 format). 7 | # attr_reader :created_at 8 | # @!attribute [r] creator_id 9 | # @return [Integer] Unique identifier of the user who created the lead. 10 | # attr_reader :creator_id 11 | # @!attribute [r] id 12 | # @return [Integer] Unique identifier of the lead. 13 | # attr_reader :id 14 | # @!attribute [r] updated_at 15 | # @return [DateTime] Date and time of the last update in UTC (ISO8601 format). 16 | # attr_reader :updated_at 17 | 18 | # @!attribute [rw] address 19 | # @return [Address] 20 | # attr_accessor :address 21 | # @!attribute [rw] custom_fields 22 | # @return [Hash] Custom fields are a either a single key-value pair attached to a lead or a set of key-value pairs attached to a lead. See more at [Custom Fields](/docs/rest/articles/requests#custom_fields). 23 | # attr_accessor :custom_fields 24 | # @!attribute [rw] description 25 | # @return [String] Lead description. 26 | # attr_accessor :description 27 | # @!attribute [rw] email 28 | # @return [String] Lead's email. 29 | # attr_accessor :email 30 | # @!attribute [rw] facebook 31 | # @return [String] Lead's Facebook nickname. 32 | # attr_accessor :facebook 33 | # @!attribute [rw] fax 34 | # @return [String] Lead's fax number. 35 | # attr_accessor :fax 36 | # @!attribute [rw] first_name 37 | # @return [String] First name of the lead. 38 | # attr_accessor :first_name 39 | # @!attribute [rw] industry 40 | # @return [String] Organization's industry. 41 | # attr_accessor :industry 42 | # @!attribute [rw] last_name 43 | # @return [String] Last name of the lead. Required unless `organization_name` field is provided. 44 | # attr_accessor :last_name 45 | # @!attribute [rw] linkedin 46 | # @return [String] Lead's Linkedin nickname. 47 | # attr_accessor :linkedin 48 | # @!attribute [rw] mobile 49 | # @return [String] Lead's mobile phone number. 50 | # attr_accessor :mobile 51 | # @!attribute [rw] organization_name 52 | # @return [String] Organization name of the lead. Required unless `last_name` field is provided. 53 | # attr_accessor :organization_name 54 | # @!attribute [rw] owner_id 55 | # @return [Integer] Unique identifier of the user who currently owns the lead. 56 | # attr_accessor :owner_id 57 | # @!attribute [rw] phone 58 | # @return [String] Lead's phone number. 59 | # attr_accessor :phone 60 | # @!attribute [rw] skype 61 | # @return [String] Lead's Skype nickname. 62 | # attr_accessor :skype 63 | # @!attribute [rw] source_id 64 | # @return [Integer] Unique identifier of the Source. 65 | # attr_accessor :source_id 66 | # @!attribute [rw] status 67 | # @return [String] Status of the lead. 68 | # attr_accessor :status 69 | # @!attribute [rw] tags 70 | # @return [Array] An array of tags for a lead. See more at [Tags](/docs/rest/articles/requests#tags). 71 | # attr_accessor :tags 72 | # @!attribute [rw] title 73 | # @return [String] Job title of the lead. 74 | # attr_accessor :title 75 | # @!attribute [rw] twitter 76 | # @return [String] Lead's Twitter handle. 77 | # attr_accessor :twitter 78 | # @!attribute [rw] website 79 | # @return [String] Lead's website. 80 | # attr_accessor :website 81 | end 82 | end 83 | -------------------------------------------------------------------------------- /lib/basecrm/models/lead_source.rb: -------------------------------------------------------------------------------- 1 | # WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | module BaseCRM 4 | class LeadSource < Model 5 | # @!attribute [r] created_at 6 | # @return [String] Date and time of creation in UTC (ISO 8601 format). 7 | # attr_reader :created_at 8 | # @!attribute [r] creator_id 9 | # @return [Integer] Unique identifier of the user that created the source. 10 | # attr_reader :creator_id 11 | # @!attribute [r] id 12 | # @return [Integer] Unique identifier of the lead source. 13 | # attr_reader :id 14 | # @!attribute [r] updated_at 15 | # @return [String] Date and time of the last update in UTC (ISO 8601 format). 16 | # attr_reader :updated_at 17 | 18 | # @!attribute [rw] name 19 | # @return [String] Name of the source. 20 | # attr_accessor :name 21 | # @!attribute [rw] resource_type 22 | # @return [String] Type name of the resource the source is attached to. Possible values: lead 23 | # attr_accessor :resource_type 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /lib/basecrm/models/lead_unqualified_reason.rb: -------------------------------------------------------------------------------- 1 | # WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | module BaseCRM 4 | class LeadUnqualifiedReason < Model 5 | # @!attribute [r] created_at 6 | # @return [DateTime] Date and time of creation in UTC ISO8601 format. 7 | # attr_reader :created_at 8 | # @!attribute [r] creator_id 9 | # @return [Integer] Unique identifier of the user the lead unqualified reason was created by. 10 | # attr_reader :creator_id 11 | # @!attribute [r] id 12 | # @return [Integer] Unique identifier of the lead unqualified reason. 13 | # attr_reader :id 14 | # @!attribute [r] updated_at 15 | # @return [DateTime] Date and time of the last update in UTC ISO8601 format. 16 | # attr_reader :updated_at 17 | 18 | # @!attribute [rw] name 19 | # @return [String] Human-friendly unqualified reason explanation. 20 | # attr_accessor :name 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /lib/basecrm/models/line_item.rb: -------------------------------------------------------------------------------- 1 | # WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | module BaseCRM 4 | class LineItem < Model 5 | # @!attribute [r] id 6 | # @return [Integer] Unique identifier of the line item. 7 | # attr_reader :id 8 | # @!attribute [r] name 9 | # @return [String] Name of the product. Value is copied from the product. 10 | # attr_reader :name 11 | # @!attribute [r] sku 12 | # @return [String] Stock Keeping Unit identification code. Value is copied from the product. 13 | # attr_reader :sku 14 | # @!attribute [r] description 15 | # @return [String] Description of the product. Value is copied from the product. 16 | # attr_reader :description 17 | # @!attribute [r] created_at 18 | # @return [DateTime] Date and time that the line item was created in UTC (ISO8601 format). 19 | # attr_reader :created_at 20 | # @!attribute [r] updated_at 21 | # @return [DateTime] Date and time of the last update on the line item in UTC (ISO8601 format). 22 | # attr_reader :updated_at 23 | 24 | # @!attribute [rw] product_id 25 | # @return [Integer] Unique identifier of the product based on which line item is created. It is not available after creation. 26 | # attr_accessor :product_id 27 | # @!attribute [rw] value 28 | # @return [Integer] Value of one unit of the product. It is product’s price after applying markup. 29 | # attr_accessor :value 30 | # @!attribute [rw] variation 31 | # @return [Integer] Variation of the product’s price for this line item. Value of 5 means that 5% markup is added, -10 means there is a 10% discount. 32 | # attr_accessor :variation 33 | # @!attribute [rw] currency 34 | # @return [String] Currency of value and price, specified in 3-character currency code (ISO4217) format. 35 | # attr_accessor :currency 36 | # @!attribute [rw] quantity 37 | # @return [Integer] Quantity of the product included in this line item. Default value is 1. 38 | # attr_accessor :quantity 39 | # @!attribute [rw] price 40 | # @return [Integer] Price of one unit of the product. Value is copied from the product. 41 | # attr_accessor :price 42 | end 43 | end 44 | -------------------------------------------------------------------------------- /lib/basecrm/models/loss_reason.rb: -------------------------------------------------------------------------------- 1 | # WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | module BaseCRM 4 | class LossReason < Model 5 | # @!attribute [r] created_at 6 | # @return [DateTime] Date and time of creation in UTC ISO8601 format. 7 | # attr_reader :created_at 8 | # @!attribute [r] creator_id 9 | # @return [Integer] Unique identifier of the user the loss reason was created by. 10 | # attr_reader :creator_id 11 | # @!attribute [r] id 12 | # @return [Integer] Unique identifier of the loss reason. 13 | # attr_reader :id 14 | # @!attribute [r] updated_at 15 | # @return [DateTime] Date and time of the last update in UTC ISO8601 format. 16 | # attr_reader :updated_at 17 | 18 | # @!attribute [rw] name 19 | # @return [String] Human-friendly loss reason explanation. 20 | # attr_accessor :name 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /lib/basecrm/models/meta.rb: -------------------------------------------------------------------------------- 1 | module BaseCRM 2 | class Meta < Model 3 | # @attribute [r] type 4 | # @return [String] An entity type. 5 | # attr_reader :type 6 | 7 | # @attribute [r] sync 8 | # @return [SyncMeta] An entity which represents sync metadata. See below for it's attributes. 9 | # attr_reader :sync 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/basecrm/models/note.rb: -------------------------------------------------------------------------------- 1 | # WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | module BaseCRM 4 | class Note < Model 5 | # @!attribute [r] created_at 6 | # @return [DateTime] Date and time of creation in UTC (ISO8601 format). 7 | # attr_reader :created_at 8 | # @!attribute [r] creator_id 9 | # @return [Integer] Unique identifier of the user that created the note. 10 | # attr_reader :creator_id 11 | # @!attribute [r] id 12 | # @return [Integer] Unique identifier of the note. 13 | # attr_reader :id 14 | # @!attribute [r] updated_at 15 | # @return [DateTime] Date and time of the last update in UTC (ISO8601 format). 16 | # attr_reader :updated_at 17 | 18 | # @!attribute [rw] content 19 | # @return [String] Content of the note. 20 | # attr_accessor :content 21 | # @!attribute [rw] resource_id 22 | # @return [Integer] Unique identifier of the resource the note is attached to. 23 | # attr_accessor :resource_id 24 | # @!attribute [rw] resource_type 25 | # @return [String] Type name of the resource the note is attached to. 26 | # attr_accessor :resource_type 27 | end 28 | end 29 | -------------------------------------------------------------------------------- /lib/basecrm/models/order.rb: -------------------------------------------------------------------------------- 1 | # WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | module BaseCRM 4 | class Order < Model 5 | # @!attribute [r] id 6 | # @return [Integer] Unique identifier of the order. 7 | # attr_reader :id 8 | # @!attribute [r] created_at 9 | # @return [DateTime] Date and time that the order was created in UTC (ISO8601 format). 10 | # attr_reader :created_at 11 | # @!attribute [r] updated_at 12 | # @return [DateTime] Date and time of the last update on the order in UTC (ISO8601 format). 13 | # attr_reader :updated_at 14 | 15 | # @!attribute [rw] deal_id 16 | # @return [Integer] ID of the deal the order is associated to. 17 | # attr_accessor :deal_id 18 | # @!attribute [rw] discount 19 | # @return [Integer] Discount on the whole order in percents. 20 | # attr_accessor :discount 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /lib/basecrm/models/pipeline.rb: -------------------------------------------------------------------------------- 1 | # WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | module BaseCRM 4 | class Pipeline < Model 5 | # @!attribute [r] created_at 6 | # @return [DateTime] Date and time of creation in UTC ISO8601 format. 7 | # attr_reader :created_at 8 | # @!attribute [r] id 9 | # @return [Integer] The unique identifier of the pipeline. 10 | # attr_reader :id 11 | # @!attribute [r] updated_at 12 | # @return [DateTime] Date and time of last update in UTC ISO8601 format. 13 | # attr_reader :updated_at 14 | 15 | # @!attribute [rw] name 16 | # @return [String] Human-friendly name of the pipeline. 17 | # attr_accessor :name 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /lib/basecrm/models/price.rb: -------------------------------------------------------------------------------- 1 | # WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | module BaseCRM 4 | class Price < Model 5 | 6 | # @!attribute [rw] amount 7 | # @return [Integer] Price amount 8 | # attr_accessor :amount 9 | # @!attribute [rw] currency 10 | # @return [String] Price currency 11 | # attr_accessor :currency 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /lib/basecrm/models/product.rb: -------------------------------------------------------------------------------- 1 | # WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | module BaseCRM 4 | class Product < Model 5 | # @!attribute [r] id 6 | # @return [Integer] Unique identifier of the product. 7 | # attr_reader :id 8 | # @!attribute [r] created_at 9 | # @return [DateTime] Date and time that the product was created in UTC (ISO8601 format). 10 | # attr_reader :created_at 11 | # @!attribute [r] updated_at 12 | # @return [DateTime] Date and time of the last update on the product in UTC (ISO8601 format). 13 | # attr_reader :updated_at 14 | 15 | # @!attribute [rw] name 16 | # @return [String] Name of the product. 17 | # attr_accessor :name 18 | # @!attribute [rw] description 19 | # @return [String] Description of the product. 20 | # attr_accessor :description 21 | # @!attribute [rw] sku 22 | # @return [String] Stock Keeping Unit identification code. 23 | # attr_accessor :sku 24 | # @!attribute [rw] active 25 | # @return [Boolean] Indicator of whether the product is active. Line items cannot be created from inactive products. 26 | # attr_accessor :active 27 | # @!attribute [rw] max_discount 28 | # @return [Integer] Maximum discount that can be applied to the product in percents. 29 | # attr_accessor :max_discount 30 | # @!attribute [rw] max_markup 31 | # @return [Integer] Maximum markup that can be applied to the product in percents. 32 | # attr_accessor :max_markup 33 | # @!attribute [rw] cost 34 | # @return [Integer] Cost of the product. Visible only to account administrators. 35 | # attr_accessor :cost 36 | # @!attribute [rw] cost_currency 37 | # @return [String] Currency of the product cost, specified in 3-character currency code (ISO4217) format. Visible only to account administrators. 38 | # attr_accessor :cost_currency 39 | # @!attribute [rw] prices 40 | # @return [Array] Array specifying products prices in different currencies. 41 | # attr_accessor :prices 42 | end 43 | end 44 | -------------------------------------------------------------------------------- /lib/basecrm/models/source.rb: -------------------------------------------------------------------------------- 1 | # WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | module BaseCRM 4 | class Source < Model 5 | # @!attribute [r] created_at 6 | # @return [String] Date and time of creation in UTC (ISO 8601 format). 7 | # attr_reader :created_at 8 | # @!attribute [r] creator_id 9 | # @return [Integer] Unique identifier of the user that created the source. 10 | # attr_reader :creator_id 11 | # @!attribute [r] id 12 | # @return [Integer] Unique identifier of the deal source. 13 | # attr_reader :id 14 | # @!attribute [r] updated_at 15 | # @return [String] Date and time of the last update in UTC (ISO 8601 format). 16 | # attr_reader :updated_at 17 | 18 | # @!attribute [rw] name 19 | # @return [String] Name of the source. 20 | # attr_accessor :name 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /lib/basecrm/models/stage.rb: -------------------------------------------------------------------------------- 1 | # WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | module BaseCRM 4 | class Stage < Model 5 | # @!attribute [r] created_at 6 | # @return [DateTime] Date and time of creation in UTC ISO8601 format. 7 | # attr_reader :created_at 8 | # @!attribute [r] id 9 | # @return [Integer] The unique identifier of the stage. 10 | # attr_reader :id 11 | # @!attribute [r] updated_at 12 | # @return [DateTime] Date and time of last update in UTC ISO8601 format. 13 | # attr_reader :updated_at 14 | 15 | # @!attribute [rw] active 16 | # @return [Boolean] Indicator whether or not the stage contains finalized deals. 17 | # attr_accessor :active 18 | # @!attribute [rw] category 19 | # @return [String] The unique category name of the stage. 20 | # attr_accessor :category 21 | # @!attribute [rw] likelihood 22 | # @return [Integer] The likelihood that a deal will be won, set for the stage as percentage. 23 | # attr_accessor :likelihood 24 | # @!attribute [rw] name 25 | # @return [String] Human-friendly name of the stage. 26 | # attr_accessor :name 27 | # @!attribute [rw] pipeline_id 28 | # @return [Integer] Unique identifier of the pipeline that contains this stage. 29 | # attr_accessor :pipeline_id 30 | # @!attribute [rw] position 31 | # @return [Integer] The stage's position in the pipeline. 32 | # attr_accessor :position 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /lib/basecrm/models/sync_meta.rb: -------------------------------------------------------------------------------- 1 | module BaseCRM 2 | class SyncMeta < Model 3 | # @attribute [r] event_type 4 | # @return [String] An event type. Possible values: `created`, `updated`, `deleted`. 5 | # attr_reader :event_type 6 | 7 | # @attribute [r] ack_key 8 | # @return [String] An acknowledgement key. 9 | # attr_reader :ack_key 10 | 11 | # @attribute [r] revision 12 | # @return [String] Data revision. 13 | # attr_reader :revision 14 | 15 | def acknowledged? 16 | !!@acknowledged 17 | end 18 | 19 | def ack 20 | @acknowledged = true 21 | [:ack, self.ack_key] 22 | end 23 | 24 | def nack 25 | @acknowledged = true 26 | [:nack, self.ack_key] 27 | end 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /lib/basecrm/models/sync_queue.rb: -------------------------------------------------------------------------------- 1 | module BaseCRM 2 | class SyncQueue < Model 3 | # @attribute [r] name 4 | # @return [String] Name of the queue. 5 | # attr_reader :name 6 | 7 | # @attribute [r] pages 8 | # @return [Integer] Number of pages to request. 9 | # attr_reader :pages 10 | 11 | # @attribute [r] total_count 12 | # @return [Integer] Total number of items in the queue to synchronize. 13 | # attr_reader :total_count 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /lib/basecrm/models/sync_session.rb: -------------------------------------------------------------------------------- 1 | module BaseCRM 2 | class SyncSession < Model 3 | # @attribute [r] id 4 | # @return [String] Unique identifier for the sync session. 5 | # attr_reader :id 6 | 7 | # @attribute [r] queues 8 | # @return [Array] A list of sync queues. 9 | # attr_reader :queues 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/basecrm/models/tag.rb: -------------------------------------------------------------------------------- 1 | # WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | module BaseCRM 4 | class Tag < Model 5 | # @!attribute [r] created_at 6 | # @return [DateTime] Date and time of creation in UTC (ISO8601 format). 7 | # attr_reader :created_at 8 | # @!attribute [r] creator_id 9 | # @return [Integer] User ID of the tag's creator. 10 | # attr_reader :creator_id 11 | # @!attribute [r] id 12 | # @return [Integer] Unique identifier of the tag. 13 | # attr_reader :id 14 | # @!attribute [r] updated_at 15 | # @return [DateTime] Date and time of the last update in UTC (ISO8601 format). 16 | # attr_reader :updated_at 17 | 18 | # @!attribute [rw] name 19 | # @return [String] Name of the tag. 20 | # attr_accessor :name 21 | # @!attribute [rw] resource_type 22 | # @return [String] Type name of the resource the tag is attached to. 23 | # attr_accessor :resource_type 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /lib/basecrm/models/task.rb: -------------------------------------------------------------------------------- 1 | # WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | module BaseCRM 4 | class Task < Model 5 | # @!attribute [r] completed_at 6 | # @return [DateTime] Date and time of the task's completion in UTC (ISO8601 format). 7 | # attr_reader :completed_at 8 | # @!attribute [r] created_at 9 | # @return [DateTime] Date and time of task creation in UTC (ISO8601 format). 10 | # attr_reader :created_at 11 | # @!attribute [r] creator_id 12 | # @return [Integer] Unique identifier of the user who created the task. 13 | # attr_reader :creator_id 14 | # @!attribute [r] id 15 | # @return [Integer] Unique identifier of the task. 16 | # attr_reader :id 17 | # @!attribute [r] overdue 18 | # @return [Boolean] Indicator for whether the task has passed the `due_date` or not. 19 | # attr_reader :overdue 20 | # @!attribute [r] updated_at 21 | # @return [DateTime] Date and time of the last update to the task in UTC (ISO8601 format). 22 | # attr_reader :updated_at 23 | 24 | # @!attribute [rw] completed 25 | # @return [Boolean] Indicator of whether the task is completed or not. 26 | # attr_accessor :completed 27 | # @!attribute [rw] content 28 | # @return [String] Content of the task. 29 | # attr_accessor :content 30 | # @!attribute [rw] due_date 31 | # @return [DateTime] Date and time of creation in UTC (ISO8601 format). 32 | # attr_accessor :due_date 33 | # @!attribute [rw] owner_id 34 | # @return [Integer] Unique identifier of the user the task is assigned to. 35 | # attr_accessor :owner_id 36 | # @!attribute [rw] remind_at 37 | # @return [DateTime] Date and time that we should send you a reminder in UTC (ISO8601 format). 38 | # attr_accessor :remind_at 39 | # @!attribute [rw] resource_id 40 | # @return [Integer] Unique identifier of the resource the task is attached to. 41 | # attr_accessor :resource_id 42 | # @!attribute [rw] resource_type 43 | # @return [String] Name of the resource type the task is attached to. 44 | # attr_accessor :resource_type 45 | end 46 | end 47 | -------------------------------------------------------------------------------- /lib/basecrm/models/text_message.rb: -------------------------------------------------------------------------------- 1 | # WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | module BaseCRM 4 | class TextMessage < Model 5 | # @!attribute [r] associated_deal_ids 6 | # @return [Array] An array of ids of deals associated to the text message. 7 | # attr_reader :associated_deal_ids 8 | # @!attribute [r] content 9 | # @return [String] Content of the text message. 10 | # attr_reader :content 11 | # @!attribute [r] created_at 12 | # @return [DateTime] Date and time of creation in UTC (ISO8601 format). 13 | # attr_reader :created_at 14 | # @!attribute [r] id 15 | # @return [Integer] Unique identifier of the text_message. 16 | # attr_reader :id 17 | # @!attribute [r] incoming 18 | # @return [Boolean] Indicator of whether the text message was incoming or not. 19 | # attr_reader :incoming 20 | # @!attribute [r] resource_id 21 | # @return [Integer] Unique identifier of the resource the text message is attached to. 22 | # attr_reader :resource_id 23 | # @!attribute [r] resource_phone_number 24 | # @return [String] Phone number of a resource the text message was sent to/received by. 25 | # attr_reader :resource_phone_number 26 | # @!attribute [r] resource_type 27 | # @return [String] Name of a resource type the text message is attached to. 28 | # attr_reader :resource_type 29 | # @!attribute [r] sent_at 30 | # @return [DateTime] Date and time of the message send time in UTC (ISO8601 format). 31 | # attr_reader :sent_at 32 | # @!attribute [r] updated_at 33 | # @return [DateTime] Date and time of the last update in UTC (ISO8601 format). 34 | # attr_reader :updated_at 35 | # @!attribute [r] user_id 36 | # @return [Integer] Unique identifier of a user who sent/received a text message. 37 | # attr_reader :user_id 38 | # @!attribute [r] user_phone_number 39 | # @return [String] Phone number of a user who sent/received a text message. 40 | # attr_reader :user_phone_number 41 | 42 | end 43 | end 44 | -------------------------------------------------------------------------------- /lib/basecrm/models/user.rb: -------------------------------------------------------------------------------- 1 | # WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | module BaseCRM 4 | class User < Model 5 | # @!attribute [r] confirmed 6 | # @return [Boolean] Indicates whether the user's account has been confirmed or not. 7 | # attr_reader :confirmed 8 | # @!attribute [r] created_at 9 | # @return [DateTime] Date and time of creation in UTC (ISO8601 format). 10 | # attr_reader :created_at 11 | # @!attribute [r] id 12 | # @return [Integer] Unique identifier of the user. 13 | # attr_reader :id 14 | # @!attribute [r] role 15 | # @return [String] Role of the user. 16 | # attr_reader :role 17 | # @!attribute [r] status 18 | # @return [String] Status of the user's account. Usually `active`. 19 | # attr_reader :status 20 | # @!attribute [r] updated_at 21 | # @return [DateTime] Date and time of the last update in UTC (ISO8601 format). 22 | # attr_reader :updated_at 23 | 24 | # @!attribute [rw] email 25 | # @return [String] Email address of the user. 26 | # attr_accessor :email 27 | # @!attribute [rw] name 28 | # @return [String] Full name of the user. 29 | # attr_accessor :name 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /lib/basecrm/models/visit.rb: -------------------------------------------------------------------------------- 1 | # WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | module BaseCRM 4 | class Visit < Model 5 | # @!attribute [r] created_at 6 | # @return [DateTime] Date and time of creation in UTC (ISO8601 format). 7 | # attr_reader :created_at 8 | # @!attribute [r] creator_id 9 | # @return [Integer] Unique identifier of a user who created a visit. 10 | # attr_reader :creator_id 11 | # @!attribute [r] id 12 | # @return [Integer] Unique identifier of a visit. 13 | # attr_reader :id 14 | # @!attribute [r] outcome_id 15 | # @return [Integer] Unique identifier of a visit outcome. 16 | # attr_reader :outcome_id 17 | # @!attribute [r] rep_location_verification_status 18 | # @return [String] The status of the location verification of the device that created the visit (sales representative). 19 | # attr_reader :rep_location_verification_status 20 | # @!attribute [r] resource_address 21 | # @return [String] Address of the visit 22 | # attr_reader :resource_address 23 | # @!attribute [r] resource_id 24 | # @return [Integer] The ID of the resource the visit is attached to. Requires the resource_type query param to be set as well. 25 | # attr_reader :resource_id 26 | # @!attribute [r] resource_type 27 | # @return [String] The type of the resource the visit is attached to. 28 | # attr_reader :resource_type 29 | # @!attribute [r] summary 30 | # @return [String] Summary of the visit. 31 | # attr_reader :summary 32 | # @!attribute [r] updated_at 33 | # @return [DateTime] Date and time of the last update in UTC (ISO8601 format). 34 | # attr_reader :updated_at 35 | 36 | end 37 | end 38 | -------------------------------------------------------------------------------- /lib/basecrm/models/visit_outcome.rb: -------------------------------------------------------------------------------- 1 | # WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | module BaseCRM 4 | class VisitOutcome < Model 5 | # @!attribute [r] created_at 6 | # @return [DateTime] Date and time of creation in UTC (ISO8601 format). 7 | # attr_reader :created_at 8 | # @!attribute [r] id 9 | # @return [Integer] Unique identifier of a visit outcome. 10 | # attr_reader :id 11 | # @!attribute [r] name 12 | # @return [String] Name of the visit outcome. 13 | # attr_reader :name 14 | # @!attribute [r] updated_at 15 | # @return [DateTime] Date and time of the last update in UTC (ISO8601 format). 16 | # attr_reader :updated_at 17 | 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /lib/basecrm/paginated_resource.rb: -------------------------------------------------------------------------------- 1 | module BaseCRM 2 | class PaginatedResource 3 | include Enumerable 4 | 5 | attr_reader :current_page 6 | 7 | def initialize(service, *args) 8 | raise TypeError unless service.respond_to?(:where) 9 | 10 | @service = service 11 | @args = args 12 | @options = args.last.kind_of?(Hash) ? args.pop : {} 13 | end 14 | 15 | def each(&block) 16 | return to_enum(:each) unless block_given? 17 | 18 | current_page = 1 19 | per_page = 25 20 | 21 | search_options = @options.merge(page: current_page, per_page: per_page) 22 | 23 | until (resources = @service.where(*@args, search_options)).empty? 24 | resources.each(&block) 25 | current_page += 1 26 | search_options[:page] = current_page 27 | end 28 | 29 | self 30 | end 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /lib/basecrm/services/accounts_service.rb: -------------------------------------------------------------------------------- 1 | # WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | module BaseCRM 4 | class AccountsService 5 | def initialize(client) 6 | @client = client 7 | end 8 | 9 | # Retrieve account details 10 | # 11 | # get '/accounts/self' 12 | # 13 | # Returns detailed information about your account 14 | # 15 | # @return [Account] Resource object. 16 | def self 17 | _, _, root = @client.get("/accounts/self") 18 | Account.new(root[:data]) 19 | end 20 | 21 | 22 | private 23 | def validate_type!(account) 24 | raise TypeError unless account.is_a?(Account) || account.is_a?(Hash) 25 | end 26 | 27 | def extract_params!(account, *args) 28 | params = account.to_h.select{ |k, _| args.include?(k) } 29 | raise ArgumentError, "one of required attributes is missing. Expected: #{args.join(',')}" if params.count != args.length 30 | params 31 | end 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /lib/basecrm/services/associated_contacts_service.rb: -------------------------------------------------------------------------------- 1 | # WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | module BaseCRM 4 | class AssociatedContactsService 5 | OPTS_KEYS_TO_PERSIST = Set[:contact_id, :role] 6 | 7 | def initialize(client) 8 | @client = client 9 | end 10 | 11 | # Retrieve deal's associated contacts 12 | # 13 | # get '/deals/{deal_id}/associated_contacts' 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(deal_id) 18 | PaginatedResource.new(self, deal_id) 19 | end 20 | 21 | # Retrieve deal's associated contacts 22 | # 23 | # get '/deals/{deal_id}/associated_contacts' 24 | # 25 | # Returns all deal associated contacts 26 | # 27 | # @param deal_id [Integer] Unique identifier of a Deal 28 | # @param options [Hash] Search options 29 | # @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. 30 | # @option options [Integer] :per_page (25) Number of records to return per page. Default limit is *25* and the maximum number that can be returned is *100*. 31 | # @return [Array] The list of AssociatedContacts for the first page, unless otherwise specified. 32 | def where(deal_id, options = {}) 33 | _, _, root = @client.get("/deals/#{deal_id}/associated_contacts", options) 34 | 35 | root[:items].map{ |item| AssociatedContact.new(item[:data]) } 36 | end 37 | 38 | 39 | # Create an associated contact 40 | # 41 | # post '/deals/{deal_id}/associated_contacts' 42 | # 43 | # Creates a deal's associated contact and its role 44 | # If the specified deal or contact does not exist, the request will return an error 45 | # 46 | # @param deal_id [Integer] Unique identifier of a Deal 47 | # @param associated_contact [AssociatedContact, Hash] Either object of the AssociatedContact type or Hash. This object's attributes describe the object to be created. 48 | # @return [AssociatedContact] The resulting object represting created resource. 49 | def create(deal_id, associated_contact) 50 | validate_type!(associated_contact) 51 | 52 | attributes = sanitize(associated_contact) 53 | _, _, root = @client.post("/deals/#{deal_id}/associated_contacts", attributes) 54 | 55 | AssociatedContact.new(root[:data]) 56 | end 57 | 58 | 59 | # Remove an associated contact 60 | # 61 | # delete '/deals/{deal_id}/associated_contacts/{contact_id}' 62 | # 63 | # Remove a deal's associated contact 64 | # If a deal with the supplied unique identifier does not exist, it returns an error 65 | # This operation cannot be undone 66 | # 67 | # @param deal_id [Integer] Unique identifier of a Deal 68 | # @param contact_id [Integer] Unique identifier of a Contact 69 | # @return [Boolean] Status of the operation. 70 | def destroy(deal_id, contact_id) 71 | status, _, _ = @client.delete("/deals/#{deal_id}/associated_contacts/#{contact_id}") 72 | status == 204 73 | end 74 | 75 | 76 | private 77 | def validate_type!(associated_contact) 78 | raise TypeError unless associated_contact.is_a?(AssociatedContact) || associated_contact.is_a?(Hash) 79 | end 80 | 81 | def extract_params!(associated_contact, *args) 82 | params = associated_contact.to_h.select{ |k, _| args.include?(k) } 83 | raise ArgumentError, "one of required attributes is missing. Expected: #{args.join(',')}" if params.count != args.length 84 | params 85 | end 86 | 87 | def sanitize(associated_contact) 88 | associated_contact.to_h.select { |k, _| OPTS_KEYS_TO_PERSIST.include?(k) } 89 | end 90 | end 91 | end 92 | -------------------------------------------------------------------------------- /lib/basecrm/services/call_outcomes_service.rb: -------------------------------------------------------------------------------- 1 | # WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | module BaseCRM 4 | class CallOutcomesService 5 | def initialize(client) 6 | @client = client 7 | end 8 | 9 | # Retrieve all call outcomes 10 | # 11 | # get '/call_outcomes' 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 call outcomes 20 | # 21 | # get '/call_outcomes' 22 | # 23 | # Returns all call outcomes available to the user, according to the parameters provided 24 | # Call outcomes are always sorted by id in ascending order 25 | # 26 | # @param options [Hash] Search options 27 | # @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. 28 | # @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*. 29 | # @return [Array] The list of CallOutcomes for the first page, unless otherwise specified. 30 | def where(options = {}) 31 | _, _, root = @client.get("/call_outcomes", options) 32 | 33 | root[:items].map{ |item| CallOutcome.new(item[:data]) } 34 | end 35 | 36 | 37 | private 38 | def validate_type!(call_outcome) 39 | raise TypeError unless call_outcome.is_a?(CallOutcome) || call_outcome.is_a?(Hash) 40 | end 41 | 42 | def extract_params!(call_outcome, *args) 43 | params = call_outcome.to_h.select{ |k, _| args.include?(k) } 44 | raise ArgumentError, "one of required attributes is missing. Expected: #{args.join(',')}" if params.count != args.length 45 | params 46 | end 47 | end 48 | end 49 | -------------------------------------------------------------------------------- /lib/basecrm/services/calls_service.rb: -------------------------------------------------------------------------------- 1 | # WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | module BaseCRM 4 | class CallsService 5 | OPTS_KEYS_TO_PERSIST = Set[:user_id, :summary, :recording_url, :outcome_id, :duration, :phone_number, :incoming, :missed, :external_id, :resource_id, :resource_type, :associated_deal_ids, :made_at] 6 | 7 | def initialize(client) 8 | @client = client 9 | end 10 | 11 | # Retrieve all calls 12 | # 13 | # get '/calls' 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 calls 22 | # 23 | # get '/calls' 24 | # 25 | # Returns all calls available to the user, according to the parameters provided 26 | # Calls are always sorted by made_at in descending order 27 | # 28 | # @param options [Hash] Search options 29 | # @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. 30 | # @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*. 31 | # @option options [String] :ids Comma-separated list of call IDs to be returned in request. 32 | # @option options [Integer] :resource_id Unique identifier of the resource the call is attached to. 33 | # @option options [String] :resource_type Name of the resource type the call is attached to. 34 | # @return [Array] The list of Calls for the first page, unless otherwise specified. 35 | def where(options = {}) 36 | _, _, root = @client.get("/calls", options) 37 | 38 | root[:items].map{ |item| Call.new(item[:data]) } 39 | end 40 | 41 | 42 | # Create a call 43 | # 44 | # post '/calls' 45 | # 46 | # Create a new call 47 | # 48 | # @param call [Call, Hash] Either object of the Call type or Hash. This object's attributes describe the object to be created. 49 | # @return [Call] The resulting object represting created resource. 50 | def create(call) 51 | validate_type!(call) 52 | 53 | attributes = sanitize(call) 54 | _, _, root = @client.post("/calls", attributes) 55 | 56 | Call.new(root[:data]) 57 | end 58 | 59 | 60 | # Retrieve a single call 61 | # 62 | # get '/calls/{id}' 63 | # 64 | # Returns a single call available to the user, according to the unique call ID provided 65 | # If the specified call does not exist, this query returns an error 66 | # 67 | # @param id [Integer] Unique identifier of a Call 68 | # @return [Call] Searched resource object. 69 | def find(id) 70 | _, _, root = @client.get("/calls/#{id}") 71 | 72 | Call.new(root[:data]) 73 | end 74 | 75 | 76 | # Update a call 77 | # 78 | # put '/calls/{id}' 79 | # 80 | # Allows to attach a Contact or Lead to an existing Call, or change it’s current association 81 | # 82 | # @param call [Call, Hash] Either object of the Call type or Hash. This object's attributes describe the object to be updated. 83 | # @return [Call] The resulting object represting updated resource. 84 | def update(call) 85 | validate_type!(call) 86 | params = extract_params!(call, :id) 87 | id = params[:id] 88 | 89 | attributes = sanitize(call) 90 | _, _, root = @client.put("/calls/#{id}", attributes) 91 | 92 | Call.new(root[:data]) 93 | end 94 | 95 | 96 | # Delete a call 97 | # 98 | # delete '/calls/{id}' 99 | # 100 | # Delete an existing call 101 | # If the specified call does not exist, this query returns an error 102 | # This operation cannot be undone 103 | # 104 | # @param id [Integer] Unique identifier of a Call 105 | # @return [Boolean] Status of the operation. 106 | def destroy(id) 107 | status, _, _ = @client.delete("/calls/#{id}") 108 | status == 204 109 | end 110 | 111 | 112 | private 113 | def validate_type!(call) 114 | raise TypeError unless call.is_a?(Call) || call.is_a?(Hash) 115 | end 116 | 117 | def extract_params!(call, *args) 118 | params = call.to_h.select{ |k, _| args.include?(k) } 119 | raise ArgumentError, "one of required attributes is missing. Expected: #{args.join(',')}" if params.count != args.length 120 | params 121 | end 122 | 123 | def sanitize(call) 124 | call.to_h.select { |k, _| OPTS_KEYS_TO_PERSIST.include?(k) } 125 | end 126 | end 127 | end 128 | -------------------------------------------------------------------------------- /lib/basecrm/services/contacts_service.rb: -------------------------------------------------------------------------------- 1 | # WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | module BaseCRM 4 | class ContactsService 5 | OPTS_KEYS_TO_PERSIST = Set[:address, :contact_id, :custom_fields, :customer_status, :description, :email, :facebook, :fax, :first_name, :industry, :is_organization, :last_name, :linkedin, :mobile, :name, :owner_id, :phone, :prospect_status, :skype, :tags, :title, :twitter, :website] 6 | 7 | def initialize(client) 8 | @client = client 9 | end 10 | 11 | # Retrieve all contacts 12 | # 13 | # get '/contacts' 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 contacts 22 | # 23 | # get '/contacts' 24 | # 25 | # Returns all contacts available to the user according to the parameters provided 26 | # 27 | # @param options [Hash] Search options 28 | # @option options [String] :"address[city]" City name. 29 | # @option options [String] :"address[country]" Country name. 30 | # @option options [String] :"address[postal_code]" Zip code or equivalent 31 | # @option options [Integer] :contact_id The unique identifier of the organization that the contact belongs to. 32 | # @option options [String] :email Email address of the contact. 33 | # @option options [String] :first_name First name of the contact. 34 | # @option options [String] :ids Comma-separated list of the IDs for the contacts you want to be returned in your request. 35 | # @option options [Boolean] :is_organization Indicates whether or not this contact refers to an organization or an individual. 36 | # @option options [String] :last_name Last name of the contact. 37 | # @option options [String] :name Name of the contact. 38 | # @option options [Integer] :page (1) The page number to start from. Page numbering is 1-based and omitting the `page` parameter will return the first page. 39 | # @option options [Integer] :per_page (25) The number of records to return per page. Default limit is *25* and maximum number that can be returned is *100*. 40 | # @option options [String] :sort_by (last_name:asc) A field to sort by. **Default** ordering is **ascending**. If you want to change the sort order to descending, append `:desc` to the field e.g. `sort_by=last_name:desc`. 41 | # @return [Array] The list of Contacts for the first page, unless otherwise specified. 42 | def where(options = {}) 43 | _, _, root = @client.get("/contacts", options) 44 | 45 | root[:items].map{ |item| Contact.new(item[:data]) } 46 | end 47 | 48 | 49 | # Create a contact 50 | # 51 | # post '/contacts' 52 | # 53 | # Create a new contact 54 | # A contact may represent a single individual or an organization 55 | # 56 | # @param contact [Contact, Hash] Either object of the Contact type or Hash. This object's attributes describe the object to be created. 57 | # @return [Contact] The resulting object represting created resource. 58 | def create(contact) 59 | validate_type!(contact) 60 | 61 | attributes = sanitize(contact) 62 | _, _, root = @client.post("/contacts", attributes) 63 | 64 | Contact.new(root[:data]) 65 | end 66 | 67 | 68 | # Retrieve a single contact 69 | # 70 | # get '/contacts/{id}' 71 | # 72 | # Returns a single contact available to the user, according to the unique contact ID provided 73 | # If the specified contact does not exist, the request will return an error 74 | # 75 | # @param id [Integer] Unique identifier of a Contact 76 | # @return [Contact] Searched resource object. 77 | def find(id) 78 | _, _, root = @client.get("/contacts/#{id}") 79 | 80 | Contact.new(root[:data]) 81 | end 82 | 83 | 84 | # Update a contact 85 | # 86 | # put '/contacts/{id}' 87 | # 88 | # Updates contact information 89 | # If the specified contact does not exist, the request will return an error 90 | # **Notice** When updating contact tags, you need to provide all tags 91 | # Any missing tag will be removed from a contact's tags 92 | # 93 | # @param contact [Contact, Hash] Either object of the Contact type or Hash. This object's attributes describe the object to be updated. 94 | # @return [Contact] The resulting object represting updated resource. 95 | def update(contact) 96 | validate_type!(contact) 97 | params = extract_params!(contact, :id) 98 | id = params[:id] 99 | 100 | attributes = sanitize(contact) 101 | _, _, root = @client.put("/contacts/#{id}", attributes) 102 | 103 | Contact.new(root[:data]) 104 | end 105 | 106 | 107 | # Delete a contact 108 | # 109 | # delete '/contacts/{id}' 110 | # 111 | # Delete an existing contact 112 | # If the specified contact does not exist, the request will return an error 113 | # This operation cannot be undone 114 | # 115 | # @param id [Integer] Unique identifier of a Contact 116 | # @return [Boolean] Status of the operation. 117 | def destroy(id) 118 | status, _, _ = @client.delete("/contacts/#{id}") 119 | status == 204 120 | end 121 | 122 | 123 | private 124 | def validate_type!(contact) 125 | raise TypeError unless contact.is_a?(Contact) || contact.is_a?(Hash) 126 | end 127 | 128 | def extract_params!(contact, *args) 129 | params = contact.to_h.select{ |k, _| args.include?(k) } 130 | raise ArgumentError, "one of required attributes is missing. Expected: #{args.join(',')}" if params.count != args.length 131 | params 132 | end 133 | 134 | def sanitize(contact) 135 | contact.to_h.select { |k, _| OPTS_KEYS_TO_PERSIST.include?(k) } 136 | end 137 | end 138 | end 139 | -------------------------------------------------------------------------------- /lib/basecrm/services/deal_sources_service.rb: -------------------------------------------------------------------------------- 1 | # WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | module BaseCRM 4 | class DealSourcesService 5 | OPTS_KEYS_TO_PERSIST = Set[:name, :resource_type] 6 | 7 | def initialize(client) 8 | @client = client 9 | end 10 | 11 | # Retrieve all sources 12 | # 13 | # get '/deal_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 '/deal_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] The list of DealSources for the first page, unless otherwise specified. 34 | def where(options = {}) 35 | _, _, root = @client.get("/deal_sources", options) 36 | 37 | root[:items].map{ |item| DealSource.new(item[:data]) } 38 | end 39 | 40 | 41 | # Create a new source 42 | # 43 | # post '/deal_sources' 44 | # 45 | # Creates a new source 46 | #
47 | # Source's name **must** be unique 48 | #
49 | # 50 | # @param deal_source [DealSource, Hash] Either object of the DealSource type or Hash. This object's attributes describe the object to be created. 51 | # @return [DealSource] The resulting object represting created resource. 52 | def create(deal_source) 53 | validate_type!(deal_source) 54 | 55 | attributes = sanitize(deal_source) 56 | _, _, root = @client.post("/deal_sources", attributes) 57 | 58 | DealSource.new(root[:data]) 59 | end 60 | 61 | 62 | # Retrieve a single source 63 | # 64 | # get '/deal_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 DealSource 70 | # @return [DealSource] Searched resource object. 71 | def find(id) 72 | _, _, root = @client.get("/deal_sources/#{id}") 73 | 74 | DealSource.new(root[:data]) 75 | end 76 | 77 | 78 | # Update a source 79 | # 80 | # put '/deal_sources/{id}' 81 | # 82 | # Updates source information 83 | # If the specified source does not exist, the request will return an error 84 | #
85 | # If you want to update a source, you **must** make sure source's name is unique 86 | #
87 | # 88 | # @param deal_source [DealSource, Hash] Either object of the DealSource type or Hash. This object's attributes describe the object to be updated. 89 | # @return [DealSource] The resulting object represting updated resource. 90 | def update(deal_source) 91 | validate_type!(deal_source) 92 | params = extract_params!(deal_source, :id) 93 | id = params[:id] 94 | 95 | attributes = sanitize(deal_source) 96 | _, _, root = @client.put("/deal_sources/#{id}", attributes) 97 | 98 | DealSource.new(root[:data]) 99 | end 100 | 101 | 102 | # Delete a source 103 | # 104 | # delete '/deal_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 DealSource 111 | # @return [Boolean] Status of the operation. 112 | def destroy(id) 113 | status, _, _ = @client.delete("/deal_sources/#{id}") 114 | status == 204 115 | end 116 | 117 | 118 | private 119 | def validate_type!(deal_source) 120 | raise TypeError unless deal_source.is_a?(DealSource) || deal_source.is_a?(Hash) 121 | end 122 | 123 | def extract_params!(deal_source, *args) 124 | params = deal_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(deal_source) 130 | deal_source.to_h.select { |k, _| OPTS_KEYS_TO_PERSIST.include?(k) } 131 | end 132 | end 133 | end 134 | -------------------------------------------------------------------------------- /lib/basecrm/services/deals_service.rb: -------------------------------------------------------------------------------- 1 | # WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | module BaseCRM 4 | class DealsService 5 | OPTS_KEYS_TO_PERSIST = Set[:contact_id, :currency, :custom_fields, :hot, :loss_reason_id, 6 | :unqualified_reason_id, :name, :owner_id, :source_id, :stage_id, :tags, :value, :last_stage_change_at, 7 | :estimated_close_date, :customized_win_likelihood, :added_on] 8 | 9 | def initialize(client) 10 | @client = client 11 | end 12 | 13 | # Retrieve all deals 14 | # 15 | # get '/deals' 16 | # 17 | # If you want to use filtering or sorting (see #where). 18 | # @return [Enumerable] Paginated resource you can use to iterate over all the resources. 19 | def all 20 | PaginatedResource.new(self) 21 | end 22 | 23 | # Retrieve all deals 24 | # 25 | # get '/deals' 26 | # 27 | # Returns all deals available to the user according to the parameters provided 28 | # 29 | # @param options [Hash] Search options 30 | # @option options [Integer] :contact_id Unique identifier of a primary contact. 31 | # @option options [Integer] :creator_id Unique identifier of the user the deal was created by. Returns all deals created by the user. 32 | # @option options [Boolean] :hot Indicator of whether or not the deal is hot. 33 | # @option options [String] :ids Comma-separated list of deal IDs to be returned in a request. 34 | # @option options [Integer] :organization_id Unique identifier of an organization. 35 | # @option options [Integer] :owner_id Unique identifier of the user the deal is owned by. Returns all deals owned by the user. 36 | # @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. 37 | # @option options [Integer] :per_page (25) Number of records to return per page. Default limit is *25* and the maximum number that can be returned is *100*. 38 | # @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=value:desc`. 39 | # @option options [Integer] :source_id Id of the Source. 40 | # @option options [Integer] :stage_id Id of the Stage. 41 | # @option options [String] :estimated_close_date of the deal. 42 | # @return [Array] The list of Deals for the first page, unless otherwise specified. 43 | def where(options = {}) 44 | _, _, root = @client.get("/deals", options) 45 | 46 | root[:items].map{ |item| Deal.new(item[:data]) } 47 | end 48 | 49 | 50 | # Create a deal 51 | # 52 | # post '/deals' 53 | # 54 | # Create a new deal 55 | # 56 | # @param deal [Deal, Hash] Either object of the Deal type or Hash. This object's attributes describe the object to be created. 57 | # @return [Deal] The resulting object represting created resource. 58 | def create(deal) 59 | validate_type!(deal) 60 | 61 | attributes = sanitize(deal) 62 | _, _, root = @client.post("/deals", attributes) 63 | 64 | Deal.new(root[:data]) 65 | end 66 | 67 | 68 | # Retrieve a single deal 69 | # 70 | # get '/deals/{id}' 71 | # 72 | # Returns a single deal available to the user, according to the unique deal ID provided 73 | # If the specified deal does not exist, the request will return an error 74 | # 75 | # @param id [Integer] Unique identifier of a Deal 76 | # @return [Deal] Searched resource object. 77 | def find(id) 78 | _, _, root = @client.get("/deals/#{id}") 79 | 80 | Deal.new(root[:data]) 81 | end 82 | 83 | 84 | # Update a deal 85 | # 86 | # put '/deals/{id}' 87 | # 88 | # Updates deal information 89 | # If the specified deal does not exist, the request will return an error 90 | #
91 | # In order to modify tags used on a record, you need to supply the entire set 92 | # `tags` are replaced every time they are used in a request 93 | #
94 | # 95 | # @param deal [Deal, Hash] Either object of the Deal type or Hash. This object's attributes describe the object to be updated. 96 | # @return [Deal] The resulting object represting updated resource. 97 | def update(deal) 98 | validate_type!(deal) 99 | params = extract_params!(deal, :id) 100 | id = params[:id] 101 | 102 | attributes = sanitize(deal) 103 | _, _, root = @client.put("/deals/#{id}", attributes) 104 | 105 | Deal.new(root[:data]) 106 | end 107 | 108 | 109 | # Delete a deal 110 | # 111 | # delete '/deals/{id}' 112 | # 113 | # Delete an existing deal and remove all of the associated contacts from the deal in a single call 114 | # If the specified deal does not exist, the request will return an error 115 | # This operation cannot be undone 116 | # 117 | # @param id [Integer] Unique identifier of a Deal 118 | # @return [Boolean] Status of the operation. 119 | def destroy(id) 120 | status, _, _ = @client.delete("/deals/#{id}") 121 | status == 204 122 | end 123 | 124 | 125 | private 126 | def validate_type!(deal) 127 | raise TypeError unless deal.is_a?(Deal) || deal.is_a?(Hash) 128 | end 129 | 130 | def extract_params!(deal, *args) 131 | params = deal.to_h.select{ |k, _| args.include?(k) } 132 | raise ArgumentError, "one of required attributes is missing. Expected: #{args.join(',')}" if params.count != args.length 133 | params 134 | end 135 | 136 | def sanitize(deal) 137 | deal_hash = deal.to_h.select { |k, _| OPTS_KEYS_TO_PERSIST.include?(k) } 138 | deal_hash[:value] = Coercion.to_string(deal_hash[:value]) if deal_hash[:value] 139 | deal_hash 140 | end 141 | end 142 | end 143 | -------------------------------------------------------------------------------- /lib/basecrm/services/lead_sources_service.rb: -------------------------------------------------------------------------------- 1 | # WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | module BaseCRM 4 | class LeadSourcesService 5 | OPTS_KEYS_TO_PERSIST = Set[:name, :resource_type] 6 | 7 | def initialize(client) 8 | @client = client 9 | end 10 | 11 | # Retrieve all sources 12 | # 13 | # get '/lead_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 '/lead_sources' 24 | # 25 | # Returns all lead 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 lead 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] The list of LeadSources for the first page, unless otherwise specified. 34 | def where(options = {}) 35 | _, _, root = @client.get("/lead_sources", options) 36 | 37 | root[:items].map{ |item| LeadSource.new(item[:data]) } 38 | end 39 | 40 | 41 | # Create a new source 42 | # 43 | # post '/lead_sources' 44 | # 45 | # Creates a new source 46 | #
47 | # Source's name **must** be unique 48 | #
49 | # 50 | # @param lead_source [LeadSource, Hash] Either object of the LeadSource type or Hash. This object's attributes describe the object to be created. 51 | # @return [LeadSource] The resulting object represting created resource. 52 | def create(lead_source) 53 | validate_type!(lead_source) 54 | 55 | attributes = sanitize(lead_source) 56 | _, _, root = @client.post("/lead_sources", attributes) 57 | 58 | LeadSource.new(root[:data]) 59 | end 60 | 61 | 62 | # Retrieve a single source 63 | # 64 | # get '/lead_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 LeadSource 70 | # @return [LeadSource] Searched resource object. 71 | def find(id) 72 | _, _, root = @client.get("/lead_sources/#{id}") 73 | 74 | LeadSource.new(root[:data]) 75 | end 76 | 77 | 78 | # Update a source 79 | # 80 | # put '/lead_sources/{id}' 81 | # 82 | # Updates source information 83 | # If the specified source does not exist, the request will return an error 84 | #
85 | # If you want to update a source, you **must** make sure source's name is unique 86 | #
87 | # 88 | # @param lead_source [LeadSource, Hash] Either object of the LeadSource type or Hash. This object's attributes describe the object to be updated. 89 | # @return [LeadSource] The resulting object represting updated resource. 90 | def update(lead_source) 91 | validate_type!(lead_source) 92 | params = extract_params!(lead_source, :id) 93 | id = params[:id] 94 | 95 | attributes = sanitize(lead_source) 96 | _, _, root = @client.put("/lead_sources/#{id}", attributes) 97 | 98 | LeadSource.new(root[:data]) 99 | end 100 | 101 | 102 | # Delete a source 103 | # 104 | # delete '/lead_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 LeadSource 111 | # @return [Boolean] Status of the operation. 112 | def destroy(id) 113 | status, _, _ = @client.delete("/lead_sources/#{id}") 114 | status == 204 115 | end 116 | 117 | 118 | private 119 | def validate_type!(lead_source) 120 | raise TypeError unless lead_source.is_a?(LeadSource) || lead_source.is_a?(Hash) 121 | end 122 | 123 | def extract_params!(lead_source, *args) 124 | params = lead_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(lead_source) 130 | lead_source.to_h.select { |k, _| OPTS_KEYS_TO_PERSIST.include?(k) } 131 | end 132 | end 133 | end 134 | -------------------------------------------------------------------------------- /lib/basecrm/services/lead_unqualified_reasons_service.rb: -------------------------------------------------------------------------------- 1 | # WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | module BaseCRM 4 | class LeadUnqualifiedReasonsService 5 | def initialize(client) 6 | @client = client 7 | end 8 | 9 | # Retrieve all lead unqualified reasons 10 | # 11 | # get '/lead_unqualified_reasons' 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 lead unqualified reasons 20 | # 21 | # get '/lead_unqualified_reasons' 22 | # 23 | # Returns all lead unqualified reasons available to the user according to the parameters provided 24 | # 25 | # @param options [Hash] Search options 26 | # @return [Array] The list of LeadUnqualifiedReasons for the first page, unless otherwise specified. 27 | def where(options = {}) 28 | _, _, root = @client.get("/lead_unqualified_reasons", options) 29 | 30 | root[:items].map{ |item| LeadUnqualifiedReason.new(item[:data]) } 31 | end 32 | 33 | 34 | private 35 | def validate_type!(lead_unqualified_reason) 36 | raise TypeError unless lead_unqualified_reason.is_a?(LeadUnqualifiedReason) || lead_unqualified_reason.is_a?(Hash) 37 | end 38 | 39 | def extract_params!(lead_unqualified_reason, *args) 40 | params = lead_unqualified_reason.to_h.select{ |k, _| args.include?(k) } 41 | raise ArgumentError, "one of required attributes is missing. Expected: #{args.join(',')}" if params.count != args.length 42 | params 43 | end 44 | end 45 | end 46 | -------------------------------------------------------------------------------- /lib/basecrm/services/leads_service.rb: -------------------------------------------------------------------------------- 1 | # WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | module BaseCRM 4 | class LeadsService 5 | OPTS_KEYS_TO_PERSIST = Set[:address, :custom_fields, :description, :email, :facebook, :fax, :first_name, :industry, :last_name, :linkedin, :mobile, :organization_name, :owner_id, :phone, :skype, :source_id, :status, :tags, :title, :twitter, :website] 6 | 7 | def initialize(client) 8 | @client = client 9 | end 10 | 11 | # Retrieve all leads 12 | # 13 | # get '/leads' 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 leads 22 | # 23 | # get '/leads' 24 | # 25 | # Returns all leads available to the user, according to the parameters provided 26 | # 27 | # @param options [Hash] Search options 28 | # @option options [String] :"address[city]" City name. 29 | # @option options [String] :"address[country]" Country name. 30 | # @option options [String] :"address[postal_code]" Zip or Postal code 31 | # @option options [Integer] :creator_id User ID. Returns all leads created by that user. 32 | # @option options [String] :first_name First name of the lead. 33 | # @option options [String] :ids Comma-separated list of lead IDs to be returned in a request. 34 | # @option options [String] :last_name Last name of the lead. 35 | # @option options [String] :organization_name Organization name of the lead. 36 | # @option options [Integer] :owner_id User ID. Returns all leads owned by that user. 37 | # @option options [Integer] :source_id ID of the Source. 38 | # @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. 39 | # @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*. 40 | # @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=last_name:desc`. 41 | # @option options [String] :status Status of the lead. 42 | # @return [Array] The list of Leads for the first page, unless otherwise specified. 43 | def where(options = {}) 44 | _, _, root = @client.get("/leads", options) 45 | 46 | root[:items].map{ |item| Lead.new(item[:data]) } 47 | end 48 | 49 | 50 | # Create a lead 51 | # 52 | # post '/leads' 53 | # 54 | # Creates a new lead 55 | # A lead may represent a single individual or an organization 56 | # 57 | # @param lead [Lead, Hash] Either object of the Lead type or Hash. This object's attributes describe the object to be created. 58 | # @return [Lead] The resulting object represting created resource. 59 | def create(lead) 60 | validate_type!(lead) 61 | 62 | attributes = sanitize(lead) 63 | _, _, root = @client.post("/leads", attributes) 64 | 65 | Lead.new(root[:data]) 66 | end 67 | 68 | 69 | # Retrieve a single lead 70 | # 71 | # get '/leads/{id}' 72 | # 73 | # Returns a single lead available to the user, according to the unique lead ID provided 74 | # If the specified lead does not exist, this query returns an error 75 | # 76 | # @param id [Integer] Unique identifier of a Lead 77 | # @return [Lead] Searched resource object. 78 | def find(id) 79 | _, _, root = @client.get("/leads/#{id}") 80 | 81 | Lead.new(root[:data]) 82 | end 83 | 84 | 85 | # Update a lead 86 | # 87 | # put '/leads/{id}' 88 | # 89 | # Updates lead information 90 | # If the specified lead does not exist, this query returns an error 91 | #
92 | # In order to modify tags, you need to supply the entire set of tags 93 | # `tags` are replaced every time they are used in a request 94 | #
95 | # 96 | # @param lead [Lead, Hash] Either object of the Lead type or Hash. This object's attributes describe the object to be updated. 97 | # @return [Lead] The resulting object represting updated resource. 98 | def update(lead) 99 | validate_type!(lead) 100 | params = extract_params!(lead, :id) 101 | id = params[:id] 102 | 103 | attributes = sanitize(lead) 104 | _, _, root = @client.put("/leads/#{id}", attributes) 105 | 106 | Lead.new(root[:data]) 107 | end 108 | 109 | 110 | # Delete a lead 111 | # 112 | # delete '/leads/{id}' 113 | # 114 | # Delete an existing lead 115 | # If the specified lead does not exist, this query returns an error 116 | # This operation cannot be undone 117 | # 118 | # @param id [Integer] Unique identifier of a Lead 119 | # @return [Boolean] Status of the operation. 120 | def destroy(id) 121 | status, _, _ = @client.delete("/leads/#{id}") 122 | status == 204 123 | end 124 | 125 | 126 | private 127 | def validate_type!(lead) 128 | raise TypeError unless lead.is_a?(Lead) || lead.is_a?(Hash) 129 | end 130 | 131 | def extract_params!(lead, *args) 132 | params = lead.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(lead) 138 | lead.to_h.select { |k, _| OPTS_KEYS_TO_PERSIST.include?(k) } 139 | end 140 | end 141 | end 142 | -------------------------------------------------------------------------------- /lib/basecrm/services/line_items_service.rb: -------------------------------------------------------------------------------- 1 | # WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | module BaseCRM 4 | class LineItemsService 5 | OPTS_KEYS_TO_PERSIST = Set[:product_id, :value, :variation, :currency, :quantity] 6 | 7 | def initialize(client) 8 | @client = client 9 | end 10 | 11 | # Retrieve order's line items 12 | # 13 | # get '/orders/{order_id}/line_items' 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(order_id) 18 | PaginatedResource.new(self, order_id) 19 | end 20 | 21 | # Retrieve order's line items 22 | # 23 | # get '/orders/{order_id}/line_items' 24 | # 25 | # Returns all line items associated to order 26 | # 27 | # @param order_id [Integer] Unique identifier of a Order 28 | # @param options [Hash] Search options 29 | # @option options [String] :ids Comma-separated list of line item IDs to be returned in a request. 30 | # @option options [Integer] :quantity Quantity of line item. 31 | # @option options [Integer] :value Value of line item. 32 | # @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. 33 | # @option options [Integer] :per_page (25) Number of records to return per page. Default limit is *25* and the maximum number that can be returned is *100*. 34 | # @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=value:desc`. 35 | # @return [Array] The list of LineItems for the first page, unless otherwise specified. 36 | def where(order_id, options = {}) 37 | _, _, root = @client.get("/orders/#{order_id}/line_items", options) 38 | 39 | root[:items].map{ |item| LineItem.new(item[:data]) } 40 | end 41 | 42 | 43 | # Create a line item 44 | # 45 | # post '/orders/{order_id}/line_items' 46 | # 47 | # Adds a new line item to an existing order 48 | # Line items correspond to products in the catalog, so first you must create products 49 | # Because products allow defining different prices in different currencies, when creating a line item, the parameter currency is required 50 | # 51 | # @param order_id [Integer] Unique identifier of a Order 52 | # @param line_item [LineItem, Hash] Either object of the LineItem type or Hash. This object's attributes describe the object to be created. 53 | # @return [LineItem] The resulting object represting created resource. 54 | def create(order_id, line_item) 55 | validate_type!(line_item) 56 | 57 | attributes = sanitize(line_item) 58 | _, _, root = @client.post("/orders/#{order_id}/line_items", attributes) 59 | 60 | LineItem.new(root[:data]) 61 | end 62 | 63 | 64 | # Retrieve a single line item 65 | # 66 | # get '/orders/{order_id}/line_items/{id}' 67 | # 68 | # Returns a single line item of an order, according to the unique line item ID provided 69 | # 70 | # @param order_id [Integer] Unique identifier of a Order 71 | # @param id [Integer] Unique identifier of a LineItem 72 | # @return [LineItem] Searched resource object. 73 | def find(order_id, id) 74 | _, _, root = @client.get("/orders/#{order_id}/line_items/#{id}") 75 | 76 | LineItem.new(root[:data]) 77 | end 78 | 79 | 80 | # Delete a line item 81 | # 82 | # delete '/orders/{order_id}/line_items/{id}' 83 | # 84 | # Remove an order’s line item 85 | # This operation cannot be undone 86 | # 87 | # @param order_id [Integer] Unique identifier of a Order 88 | # @param id [Integer] Unique identifier of a LineItem 89 | # @return [Boolean] Status of the operation. 90 | def destroy(order_id, id) 91 | status, _, _ = @client.delete("/orders/#{order_id}/line_items/#{id}") 92 | status == 204 93 | end 94 | 95 | 96 | private 97 | def validate_type!(line_item) 98 | raise TypeError unless line_item.is_a?(LineItem) || line_item.is_a?(Hash) 99 | end 100 | 101 | def extract_params!(line_item, *args) 102 | params = line_item.to_h.select{ |k, _| args.include?(k) } 103 | raise ArgumentError, "one of required attributes is missing. Expected: #{args.join(',')}" if params.count != args.length 104 | params 105 | end 106 | 107 | def sanitize(line_item) 108 | line_item.to_h.select { |k, _| OPTS_KEYS_TO_PERSIST.include?(k) } 109 | end 110 | end 111 | end 112 | -------------------------------------------------------------------------------- /lib/basecrm/services/loss_reasons_service.rb: -------------------------------------------------------------------------------- 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] 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 | #
47 | # Loss reason's name **must** be unique 48 | #
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 | #
85 | # If you want to update loss reason you **must** make sure name of the reason is unique 86 | #
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 134 | -------------------------------------------------------------------------------- /lib/basecrm/services/notes_service.rb: -------------------------------------------------------------------------------- 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] 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 135 | -------------------------------------------------------------------------------- /lib/basecrm/services/orders_service.rb: -------------------------------------------------------------------------------- 1 | # WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | module BaseCRM 4 | class OrdersService 5 | OPTS_KEYS_TO_PERSIST = Set[:deal_id, :discount] 6 | 7 | def initialize(client) 8 | @client = client 9 | end 10 | 11 | # Retrieve all orders 12 | # 13 | # get '/orders' 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 orders 22 | # 23 | # get '/orders' 24 | # 25 | # Returns all orders 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 order IDs to be returned in a request. 29 | # @option options [Integer] :deal_id ID of the deal order is associated to. 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. 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. **Default** ordering is **ascending**. If you want to change the sort ordering to descending, append `:desc` to the field e.g. `sort_by=value:desc`. 33 | # @return [Array] The list of Orders for the first page, unless otherwise specified. 34 | def where(options = {}) 35 | _, _, root = @client.get("/orders", options) 36 | 37 | root[:items].map{ |item| Order.new(item[:data]) } 38 | end 39 | 40 | 41 | # Create an order 42 | # 43 | # post '/orders' 44 | # 45 | # Create a new order for a deal 46 | # User needs to have access to the deal to create an order 47 | # Each deal can have at most one order and error is returned when attempting to create more 48 | # 49 | # @param order [Order, Hash] Either object of the Order type or Hash. This object's attributes describe the object to be created. 50 | # @return [Order] The resulting object represting created resource. 51 | def create(order) 52 | validate_type!(order) 53 | 54 | attributes = sanitize(order) 55 | _, _, root = @client.post("/orders", attributes) 56 | 57 | Order.new(root[:data]) 58 | end 59 | 60 | 61 | # Retrieve a single order 62 | # 63 | # get '/orders/{id}' 64 | # 65 | # Returns a single order available to the user, according to the unique order ID provided 66 | # If the specified order does not exist, the request will return an error 67 | # 68 | # @param id [Integer] Unique identifier of a Order 69 | # @return [Order] Searched resource object. 70 | def find(id) 71 | _, _, root = @client.get("/orders/#{id}") 72 | 73 | Order.new(root[:data]) 74 | end 75 | 76 | 77 | # Update an order 78 | # 79 | # put '/orders/{id}' 80 | # 81 | # Updates order information 82 | # If the specified order does not exist, the request will return an error 83 | # 84 | # @param order [Order, Hash] Either object of the Order type or Hash. This object's attributes describe the object to be updated. 85 | # @return [Order] The resulting object represting updated resource. 86 | def update(order) 87 | validate_type!(order) 88 | params = extract_params!(order, :id) 89 | id = params[:id] 90 | 91 | attributes = sanitize(order) 92 | _, _, root = @client.put("/orders/#{id}", attributes) 93 | 94 | Order.new(root[:data]) 95 | end 96 | 97 | 98 | # Delete an order 99 | # 100 | # delete '/orders/{id}' 101 | # 102 | # Delete an existing order and remove all of the associated line items in a single call 103 | # If the specified order does not exist, the request will return an error 104 | # This operation cannot be undone 105 | # 106 | # @param id [Integer] Unique identifier of a Order 107 | # @return [Boolean] Status of the operation. 108 | def destroy(id) 109 | status, _, _ = @client.delete("/orders/#{id}") 110 | status == 204 111 | end 112 | 113 | 114 | private 115 | def validate_type!(order) 116 | raise TypeError unless order.is_a?(Order) || order.is_a?(Hash) 117 | end 118 | 119 | def extract_params!(order, *args) 120 | params = order.to_h.select{ |k, _| args.include?(k) } 121 | raise ArgumentError, "one of required attributes is missing. Expected: #{args.join(',')}" if params.count != args.length 122 | params 123 | end 124 | 125 | def sanitize(order) 126 | order.to_h.select { |k, _| OPTS_KEYS_TO_PERSIST.include?(k) } 127 | end 128 | end 129 | end 130 | -------------------------------------------------------------------------------- /lib/basecrm/services/pipelines_service.rb: -------------------------------------------------------------------------------- 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] 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 51 | -------------------------------------------------------------------------------- /lib/basecrm/services/products_service.rb: -------------------------------------------------------------------------------- 1 | # WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | module BaseCRM 4 | class ProductsService 5 | OPTS_KEYS_TO_PERSIST = Set[:name, :description, :sku, :active, :cost, :cost_currency, :prices, :max_discount, :max_markup] 6 | 7 | def initialize(client) 8 | @client = client 9 | end 10 | 11 | # Retrieve all products 12 | # 13 | # get '/products' 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 products 22 | # 23 | # get '/products' 24 | # 25 | # Returns all products 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 product IDs to be returned in a request. 29 | # @option options [Integer] :organization_id Unique identifier of an organization. 30 | # @option options [Integer] :owner_id Unique identifier of the user the product is owned by. Returns all products owned by the user. 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. Default limit is *25* and the maximum number that can be returned is *100*. 33 | # @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=value:desc`. 34 | # @option options [String] :name Name of the product. 35 | # @option options [String] :sku SKU of the product. 36 | # @option options [Boolean] :active Indicator of whether or not the product is active. 37 | # @return [Array] The list of Products for the first page, unless otherwise specified. 38 | def where(options = {}) 39 | _, _, root = @client.get("/products", options) 40 | 41 | root[:items].map{ |item| Product.new(item[:data]) } 42 | end 43 | 44 | 45 | # Create a product 46 | # 47 | # post '/products' 48 | # 49 | # Create a new product 50 | # 51 | # @param product [Product, Hash] Either object of the Product type or Hash. This object's attributes describe the object to be created. 52 | # @return [Product] The resulting object represting created resource. 53 | def create(product) 54 | validate_type!(product) 55 | 56 | attributes = sanitize(product) 57 | _, _, root = @client.post("/products", attributes) 58 | 59 | Product.new(root[:data]) 60 | end 61 | 62 | 63 | # Retrieve a single product 64 | # 65 | # get '/products/{id}' 66 | # 67 | # Returns a single product, according to the unique product ID provided 68 | # If the specified product does not exist, the request will return an error 69 | # 70 | # @param id [Integer] Unique identifier of a Product 71 | # @return [Product] Searched resource object. 72 | def find(id) 73 | _, _, root = @client.get("/products/#{id}") 74 | 75 | Product.new(root[:data]) 76 | end 77 | 78 | 79 | # Update a product 80 | # 81 | # put '/products/{id}' 82 | # 83 | # Updates product information 84 | # If the specified product does not exist, the request will return an error 85 | #

In order to modify prices used on a record, you need to supply the entire set 86 | # prices are replaced every time they are used in a request 87 | #

88 | # 89 | # @param product [Product, Hash] Either object of the Product type or Hash. This object's attributes describe the object to be updated. 90 | # @return [Product] The resulting object represting updated resource. 91 | def update(product) 92 | validate_type!(product) 93 | params = extract_params!(product, :id) 94 | id = params[:id] 95 | 96 | attributes = sanitize(product) 97 | _, _, root = @client.put("/products/#{id}", attributes) 98 | 99 | Product.new(root[:data]) 100 | end 101 | 102 | 103 | # Delete a product 104 | # 105 | # delete '/products/{id}' 106 | # 107 | # Delete an existing product from the catalog 108 | # Existing orders and line items are not affected 109 | # If the specified product does not exist, the request will return an error 110 | # This operation cannot be undone 111 | # Products can be removed only by an account administrator 112 | # 113 | # @param id [Integer] Unique identifier of a Product 114 | # @return [Boolean] Status of the operation. 115 | def destroy(id) 116 | status, _, _ = @client.delete("/products/#{id}") 117 | status == 204 118 | end 119 | 120 | 121 | private 122 | def validate_type!(product) 123 | raise TypeError unless product.is_a?(Product) || product.is_a?(Hash) 124 | end 125 | 126 | def extract_params!(product, *args) 127 | params = product.to_h.select{ |k, _| args.include?(k) } 128 | raise ArgumentError, "one of required attributes is missing. Expected: #{args.join(',')}" if params.count != args.length 129 | params 130 | end 131 | 132 | def sanitize(product) 133 | product.to_h.select { |k, _| OPTS_KEYS_TO_PERSIST.include?(k) } 134 | end 135 | end 136 | end 137 | -------------------------------------------------------------------------------- /lib/basecrm/services/sources_service.rb: -------------------------------------------------------------------------------- 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] 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 | #
47 | # Source's name **must** be unique 48 | #
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 | #
85 | # If you want to update a source, you **must** make sure source's name is unique 86 | #
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 134 | -------------------------------------------------------------------------------- /lib/basecrm/services/stages_service.rb: -------------------------------------------------------------------------------- 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] 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 53 | -------------------------------------------------------------------------------- /lib/basecrm/services/sync_service.rb: -------------------------------------------------------------------------------- 1 | module BaseCRM 2 | class SyncService 3 | 4 | def initialize(client) 5 | @client = client 6 | end 7 | 8 | # Start synchronization flow 9 | # 10 | # post '/sync/start' 11 | # 12 | # Starts a new synchronization session. 13 | # This is the first endpoint to call, in order to start a new synchronization session. 14 | # 15 | # @param device_uuid [String] Device's UUID for which to perform synchronization. 16 | # @return [SyncSession] The resulting object is the synchronization session object or nil if there is nothing to synchronize. 17 | def start(device_uuid) 18 | validate_device!(device_uuid) 19 | 20 | status, _, root = @client.post("/sync/start", {}, build_headers(device_uuid)) 21 | return nil if status == 204 22 | 23 | build_session(root) 24 | end 25 | 26 | # Get data from queue 27 | # 28 | # get '/sync/{session_id}/queues/main' 29 | # 30 | # Fetch fresh data from the main queue. 31 | # Using session identifier you call continously the `#fetch` method to drain the main queue. 32 | # 33 | # @param device_uuid [String] Device's UUID for which to perform synchronization 34 | # @param session_id [String] Unique identifier of a synchronization session. 35 | # @param queue [String|Symbol] Queue name. 36 | # @return [Array>] The list of sync's metadata associated with data and data, or nil if nothing more to synchronize. 37 | def fetch(device_uuid, session_id, queue='main') 38 | validate_device!(device_uuid) 39 | raise ArgumentError, "session_id must not be nil nor empty" unless session_id && !session_id.strip.empty? 40 | raise ArgumentError, "queue name must not be nil nor empty" unless queue && !queue.strip.empty? 41 | 42 | status, _, root = @client.get("/sync/#{session_id}/queues/#{queue}", {}, build_headers(device_uuid)) 43 | return nil if status == 204 44 | 45 | root[:items].map do |item| 46 | klass = classify_type(item[:meta][:type]) 47 | next unless klass 48 | [build_meta(item[:meta]), klass.new(item[:data])] 49 | end 50 | end 51 | 52 | # Acknowledge received data 53 | # 54 | # post '/sync/ack' 55 | # 56 | # Send acknowledgement keys to let know the Sync service which data you have. 57 | # As you fetch new data, you need to send acknowledgement keys. 58 | # 59 | # @param device_uuid [String] Device's UUID for which to perform synchronization. 60 | # @param ack_keys [Array] The list of acknowledgement keys. 61 | # @return [Boolean] Status of the operation. 62 | def ack(device_uuid, ack_keys) 63 | validate_device!(device_uuid) 64 | raise ArgumentError, "ack_keys must not be nil and an array" unless ack_keys && ack_keys.is_a?(Array) 65 | return true if ack_keys.empty? 66 | 67 | payload = { 68 | :ack_keys => ack_keys.map(&:to_s) 69 | } 70 | status, _, _ = @client.post('/sync/ack', payload, build_headers(device_uuid)) 71 | status == 202 72 | end 73 | 74 | private 75 | def validate_device!(device_uuid) 76 | raise ArgumentError, "device_uuid must not be nil nor empty" unless device_uuid && !device_uuid.strip.empty? 77 | end 78 | 79 | def build_headers(device_uuid) 80 | { 81 | "X-Basecrm-Device-UUID" => device_uuid, 82 | "X-Client-Type" => 'api', 83 | "X-Client-Version" => BaseCRM::VERSION, 84 | "X-Device-Id" => 'Ruby' 85 | } 86 | end 87 | 88 | def classify_type(type) 89 | return nil unless type && !type.empty? 90 | BaseCRM.const_get(type.split('_').map(&:capitalize).join) rescue nil 91 | end 92 | 93 | def build_session(root) 94 | session_data = root[:data] 95 | session_data[:queues] = session_data[:queues].map { |queue| SyncQueue.new(queue[:data]) } 96 | SyncSession.new(session_data) 97 | end 98 | 99 | def build_meta(meta) 100 | Meta.new(meta.merge(sync: SyncMeta.new(meta[:sync]))) 101 | end 102 | end 103 | end 104 | -------------------------------------------------------------------------------- /lib/basecrm/services/tags_service.rb: -------------------------------------------------------------------------------- 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] 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 133 | -------------------------------------------------------------------------------- /lib/basecrm/services/text_messages_service.rb: -------------------------------------------------------------------------------- 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] 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 68 | -------------------------------------------------------------------------------- /lib/basecrm/services/users_service.rb: -------------------------------------------------------------------------------- 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] 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 84 | -------------------------------------------------------------------------------- /lib/basecrm/services/visit_outcomes_service.rb: -------------------------------------------------------------------------------- 1 | # WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | module BaseCRM 4 | class VisitOutcomesService 5 | def initialize(client) 6 | @client = client 7 | end 8 | 9 | # Retrieve visit outcomes 10 | # 11 | # get '/visit_outcomes' 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 visit outcomes 20 | # 21 | # get '/visit_outcomes' 22 | # 23 | # Returns Visit Outcomes, 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 | # @return [Array] The list of VisitOutcomes for the first page, unless otherwise specified. 29 | def where(options = {}) 30 | _, _, root = @client.get("/visit_outcomes", options) 31 | 32 | root[:items].map{ |item| VisitOutcome.new(item[:data]) } 33 | end 34 | 35 | 36 | private 37 | def validate_type!(visit_outcome) 38 | raise TypeError unless visit_outcome.is_a?(VisitOutcome) || visit_outcome.is_a?(Hash) 39 | end 40 | 41 | def extract_params!(visit_outcome, *args) 42 | params = visit_outcome.to_h.select{ |k, _| args.include?(k) } 43 | raise ArgumentError, "one of required attributes is missing. Expected: #{args.join(',')}" if params.count != args.length 44 | params 45 | end 46 | end 47 | end 48 | -------------------------------------------------------------------------------- /lib/basecrm/services/visits_service.rb: -------------------------------------------------------------------------------- 1 | # WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | module BaseCRM 4 | class VisitsService 5 | def initialize(client) 6 | @client = client 7 | end 8 | 9 | # Retrieve visits 10 | # 11 | # get '/visits' 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 visits 20 | # 21 | # get '/visits' 22 | # 23 | # Returns Visits, 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 [Integer] :outcome_id Unique identifier of a visit outcome. 29 | # @option options [Integer] :creator_id Unique identifier of a user who created a visit. 30 | # @option options [Integer] :resource_id Unique identifier of a resource the visit is attached to. Requires also resource_type to be specified. 31 | # @option options [String] :resource_type Name of a resource type the visit is attached to. Requires also resource_id to be specified. 32 | # @option options [String] :rep_location_verification_status The status of the location verification of the device that created the visit (sales representative). 33 | # @option options [String] :sort_by (id:asc) A field to sort by. Default ordering is ascending. If you want to change the sort order to descending, append :desc to the filed e.g. sort_by=visited_at:desc. 34 | # @return [Array] The list of Visits for the first page, unless otherwise specified. 35 | def where(options = {}) 36 | _, _, root = @client.get("/visits", options) 37 | 38 | root[:items].map{ |item| Visit.new(item[:data]) } 39 | end 40 | 41 | 42 | private 43 | def validate_type!(visit) 44 | raise TypeError unless visit.is_a?(Visit) || visit.is_a?(Hash) 45 | end 46 | 47 | def extract_params!(visit, *args) 48 | params = visit.to_h.select{ |k, _| args.include?(k) } 49 | raise ArgumentError, "one of required attributes is missing. Expected: #{args.join(',')}" if params.count != args.length 50 | params 51 | end 52 | end 53 | end 54 | -------------------------------------------------------------------------------- /lib/basecrm/sync.rb: -------------------------------------------------------------------------------- 1 | module BaseCRM 2 | class Sync 3 | attr_reader :device_uuid 4 | attr_reader :client 5 | 6 | # Intantiate a new BaseCRM Sync API V2 high-level wrapper 7 | # 8 | # @param options[Hash] Wrapper options 9 | # @option options [String] :device_uuid Device's UUID. 10 | # @option options [BaseCRM::Client] :client BaseCRM API v2 client instance. 11 | # 12 | # @raise [ConfigurationError] if no device's uuid provided 13 | # @raise [ConfigurationError] if no client instance provided 14 | # 15 | # @return [Sync] New wrapper instance 16 | # 17 | # @see Client 18 | # @see SyncService 19 | def initialize(options) 20 | @device_uuid = options[:device_uuid] 21 | @client = options[:client] 22 | 23 | validate! 24 | end 25 | 26 | # Perform a full synchronization flow. 27 | # See the following example: 28 | # 29 | # client = BaseCRM::Client.new(access_token: "") 30 | # sync = BaseCRM::Sync.new(client: client, device_uuid: "") 31 | # sync.fetch do |meta, resource| 32 | # DB.send(meta.sync.event_type, entity) ? meta.sync.ack : meta.sync.nack 33 | # end 34 | # 35 | # @param block [Proc] Procedure that will be called for every item in the queue. Takes two input arguments: SyncMeta instance 36 | # associated with the resource, and the resource. You should use either `SyncQueue#ack` or `SyncQueue#nack` to return value from the block. 37 | # 38 | # @return nil 39 | def fetch(&block) 40 | return unless block_given? 41 | 42 | # Set up a new synchronization session for given device's UUID 43 | session = @client.sync.start(@device_uuid) 44 | 45 | # Check if there is anything to synchronize 46 | return unless session && session.id 47 | 48 | # Drain the main queue unitl there is no more data (empty array) 49 | loop do 50 | queued_data = @client.sync.fetch(@device_uuid, session.id) 51 | 52 | # nothing more to synchronize ? 53 | break unless queued_data 54 | 55 | # something bad at the backend 56 | next if queued_data.empty? 57 | 58 | ack_keys = [] 59 | queued_data.each do |sync_meta, resource| 60 | op, ack_key = block.call(sync_meta, resource) 61 | ack_keys << ack_key if op == :ack 62 | end 63 | 64 | # As we fetch new data, we need to send ackwledgement keys - if any 65 | @client.sync.ack(@device_uuid, ack_keys) unless ack_keys.empty? 66 | end 67 | end 68 | 69 | private 70 | def validate! 71 | unless @device_uuid 72 | raise ConfigurationError.new('No device UUID provided. '\ 73 | 'The UUID must not change between synchronization sessions. '\ 74 | 'Set your device\'s UUID during wrapper initialization using: '\ 75 | '"Base::Sync.new(device_uuid: , client: client)".') 76 | end 77 | 78 | unless @client 79 | raise ConfigurationError.new('No "BaseCRM::Client" instance provided. '\ 80 | 'The high-level sync wrapper is using "BaseCRM::SyncService"\'s lowl-level interface '\ 81 | 'exposed within "BaseCRM::Client" scope.') 82 | end 83 | end 84 | end 85 | end 86 | -------------------------------------------------------------------------------- /lib/basecrm/utils/coercion.rb: -------------------------------------------------------------------------------- 1 | require "bigdecimal" 2 | 3 | module BaseCRM 4 | class Coercion 5 | def self.to_decimal_value(value) 6 | BigDecimal((value || 0), 15) 7 | end 8 | 9 | def self.to_string(value) 10 | case value 11 | when BigDecimal then value.to_s('F') 12 | else value.to_s 13 | end 14 | end 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /lib/basecrm/version.rb: -------------------------------------------------------------------------------- 1 | module BaseCRM 2 | VERSION = "2.0.0" 3 | end 4 | -------------------------------------------------------------------------------- /spec/basecrm/sync_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe BaseCRM::Sync do 4 | let(:device_uuid) { '6dadcec8-6e61-4691-b318-1aab27b8fecf' } 5 | let(:session_id) { '29f2aeeb-8d68-4ea7-95c3-a2c8e151f5a3' } 6 | 7 | subject { BaseCRM::Sync.new(device_uuid: device_uuid, client: client) } 8 | 9 | describe 'Responds to' do 10 | it { should respond_to :fetch } 11 | end 12 | 13 | describe :initialize do 14 | describe 'validation' do 15 | context 'no device_uuid option' do 16 | it 'raises BaseCRM::ConfigurationError exception' do 17 | expect { BaseCRM::Sync.new(client: client) }.to raise_error BaseCRM::ConfigurationError 18 | end 19 | end 20 | 21 | context 'no client option' do 22 | it 'raises BaseCRM::ConfigurationError exception' do 23 | expect { BaseCRM::Sync.new(device_uuid: device_uuid) }.to raise_error BaseCRM::ConfigurationError 24 | end 25 | end 26 | 27 | context 'required options passed' do 28 | it 'raises no exception' do 29 | expect { BaseCRM::Sync.new(client: client, device_uuid: device_uuid) }.not_to raise_error 30 | end 31 | end 32 | end 33 | end 34 | 35 | describe :fetch do 36 | context 'no block passed' do 37 | it 'does nothing' do 38 | expect(client).not_to receive(:sync) 39 | subject.fetch 40 | end 41 | end 42 | 43 | context 'nothing to synchronize' do 44 | before :each do 45 | expect(client.sync).to receive(:start).with(device_uuid).and_return(nil) 46 | end 47 | 48 | it 'returns early' do 49 | expect(subject.fetch { |s, r| :nop }).to be_nil 50 | end 51 | end 52 | 53 | context 'fresh data to synchronize' do 54 | let(:session) do 55 | BaseCRM::SyncSession.new(id: session_id) 56 | end 57 | 58 | let(:ack_keys) do 59 | ['User-1234-1', 'Source-1234-1'] 60 | end 61 | 62 | let(:queue_items) do 63 | [ 64 | [BaseCRM::Meta.new(type: 'user', sync: BaseCRM::SyncMeta.new(event_type: 'created', ack_key: 'User-1234-1')), BaseCRM::User.new(id: 1)], 65 | [BaseCRM::Meta.new(type: 'source', sync: BaseCRM::SyncMeta.new(event_type: 'created', ack_key: 'Source-1234-1')), BaseCRM::Source.new(id: 1)] 66 | ] 67 | end 68 | 69 | before :each do 70 | expect(client.sync).to receive(:start).with(device_uuid).and_return(session) 71 | expect(client.sync).to receive(:fetch).with(device_uuid, session_id).and_return(queue_items) 72 | expect(client.sync).to receive(:fetch).with(device_uuid, session_id).and_return([]) 73 | expect(client.sync).to receive(:fetch).with(device_uuid, session_id).and_return(nil) 74 | expect(client.sync).to receive(:ack).with(device_uuid, ack_keys).and_return(true) 75 | end 76 | 77 | it 'does whole synchronization flow' do 78 | subject.fetch { |m, r| m.sync.ack } 79 | end 80 | 81 | it 'calls a provided block as many times as items in the queue' do 82 | counter = 0 83 | subject.fetch { |m, r| counter += 1; m.sync.ack } 84 | expect(counter).to eq(2) 85 | end 86 | 87 | it 'passes two elements to provided block: first element is BaseCRM::SyncMeta and the second is a resource' do 88 | subject.fetch do |m, r| 89 | expect(m).to be_a BaseCRM::Meta 90 | expect(m.sync).to be_a BaseCRM::SyncMeta 91 | m.sync.ack 92 | end 93 | end 94 | end 95 | end 96 | end 97 | -------------------------------------------------------------------------------- /spec/factories/associated_contact.rb: -------------------------------------------------------------------------------- 1 | FactoryBot.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 15 | -------------------------------------------------------------------------------- /spec/factories/call.rb: -------------------------------------------------------------------------------- 1 | require 'securerandom' 2 | 3 | FactoryBot.define do 4 | factory :call, class: BaseCRM::Call do 5 | 6 | summary { "Schedule another call." } 7 | recording_url { "https://api.twilio.com/2010-04-01/Accounts/hAkjsahhd719e/Recordings/RKOHurusajda" } 8 | duration { 44 } 9 | phone_number { "+44-208-1234567" } 10 | incoming { true } 11 | missed { false } 12 | external_id { SecureRandom.hex(32) } 13 | made_at { "2014-09-27T16:32:56+00:00" } 14 | 15 | 16 | to_create do |call| 17 | client.calls.create(call) 18 | end 19 | end 20 | end 21 | -------------------------------------------------------------------------------- /spec/factories/contact.rb: -------------------------------------------------------------------------------- 1 | FactoryBot.define do 2 | factory :contact, class: BaseCRM::Contact do 3 | 4 | description { "I know him via Tom" } 5 | email { "mark#{SecureRandom.hex}@example.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.example.com" } 21 | 22 | 23 | to_create do |contact| 24 | client.contacts.create(contact) 25 | end 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /spec/factories/deal.rb: -------------------------------------------------------------------------------- 1 | FactoryBot.define do 2 | factory :deal, class: BaseCRM::Deal do 3 | 4 | currency { "EUR" } 5 | dropbox_email { "dropbox@4e627bcd.deals.futuresimple.com" } 6 | hot { true } 7 | name { Faker::Name.name } 8 | tags { ["important"] } 9 | value { 1000 } 10 | 11 | contact_id { contact.id } 12 | 13 | to_create do |deal| 14 | client.deals.create(deal) 15 | end 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /spec/factories/deal_source.rb: -------------------------------------------------------------------------------- 1 | FactoryBot.define do 2 | factory :deal_source, class: BaseCRM::DealSource do 3 | 4 | name { "source#{SecureRandom.hex}" } 5 | 6 | 7 | to_create do |deal_source| 8 | client.deal_sources.create(deal_source) 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /spec/factories/deal_unqualified_reason.rb: -------------------------------------------------------------------------------- 1 | FactoryBot.define do 2 | factory :deal_unqualified_reason, class: BaseCRM::DealUnqualifiedReason do 3 | 4 | name { "unqualified_reason#{SecureRandom.hex}" } 5 | 6 | 7 | to_create do |deal_unqualified_reason| 8 | client.deal_unqualified_reasons.create(deal_unqualified_reason) 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /spec/factories/lead.rb: -------------------------------------------------------------------------------- 1 | FactoryBot.define do 2 | factory :lead, class: BaseCRM::Lead do 3 | 4 | description { "I know him via Tom" } 5 | email { "mark#{SecureRandom.hex}@example.com" } 6 | facebook { "mjohnson" } 7 | fax { "+44-208-1234567" } 8 | first_name { Faker::Name.first_name } 9 | industry { "Design Services" } 10 | last_name { Faker::Name.last_name } 11 | linkedin { "mjohnson" } 12 | mobile { "508-778-6516" } 13 | phone { "508-778-6516" } 14 | skype { "mjohnson" } 15 | status { "Unqualified" } 16 | tags { ["important"] } 17 | title { "CEO" } 18 | twitter { "mjohnson" } 19 | website { "www.example.com" } 20 | 21 | 22 | to_create do |lead| 23 | client.leads.create(lead) 24 | end 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /spec/factories/lead_source.rb: -------------------------------------------------------------------------------- 1 | FactoryBot.define do 2 | factory :lead_source, class: BaseCRM::LeadSource do 3 | 4 | name { "source#{SecureRandom.hex}" } 5 | 6 | 7 | to_create do |lead_source| 8 | client.lead_sources.create(lead_source) 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /spec/factories/lead_unqualified_reason.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zendesk/basecrm-ruby/a031e48c7ad4edde28f0e870db14130479dd5b2d/spec/factories/lead_unqualified_reason.rb -------------------------------------------------------------------------------- /spec/factories/line_item.rb: -------------------------------------------------------------------------------- 1 | FactoryBot.define do 2 | factory :line_item, class: BaseCRM::LineItem do 3 | # transient attributes, required in url 4 | order_id { nil } 5 | 6 | product_id { 5 } 7 | value { 1599.99 } 8 | variation { 0 } 9 | currency { "USD" } 10 | quantity { 1 } 11 | price { 1599.99 } 12 | 13 | 14 | to_create do |line_item| 15 | client.line_items.create(line_item.order_id, line_item) 16 | end 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /spec/factories/loss_reason.rb: -------------------------------------------------------------------------------- 1 | FactoryBot.define do 2 | factory :loss_reason, class: BaseCRM::LossReason do 3 | 4 | name { "loss_reason#{Time.now.to_i}" } 5 | 6 | 7 | to_create do |loss_reason| 8 | client.loss_reasons.create(loss_reason) 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /spec/factories/note.rb: -------------------------------------------------------------------------------- 1 | FactoryBot.define do 2 | factory :note, class: BaseCRM::Note do 3 | 4 | content { "Highly important." } 5 | 6 | resource_id { contact.id } 7 | resource_type { :contact } 8 | 9 | to_create do |note| 10 | client.notes.create(note) 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /spec/factories/order.rb: -------------------------------------------------------------------------------- 1 | FactoryBot.define do 2 | factory :order, class: BaseCRM::Order do 3 | 4 | deal_id { 5 } 5 | discount { 4 } 6 | 7 | 8 | to_create do |order| 9 | client.orders.create(order) 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /spec/factories/product.rb: -------------------------------------------------------------------------------- 1 | FactoryBot.define do 2 | factory :product, class: BaseCRM::Product do 3 | 4 | name { Faker::Name.name } 5 | description { "Includes more storage options" } 6 | sku { "enterprise-plan" } 7 | active { true } 8 | max_discount { 100 } 9 | max_markup { 200 } 10 | cost { 1599.99 } 11 | cost_currency { "USD" } 12 | prices { [{"amount"=>"1599.99", "currency"=>"USD"}, {"amount"=>"3599.99", "currency"=>"PLN"}] } 13 | 14 | 15 | to_create do |product| 16 | client.products.create(product) 17 | end 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /spec/factories/source.rb: -------------------------------------------------------------------------------- 1 | FactoryBot.define do 2 | factory :source, class: BaseCRM::Source do 3 | 4 | name { "source#{SecureRandom.hex}" } 5 | 6 | 7 | to_create do |source| 8 | client.sources.create(source) 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /spec/factories/tag.rb: -------------------------------------------------------------------------------- 1 | FactoryBot.define do 2 | factory :tag, class: BaseCRM::Tag do 3 | 4 | name { "tag#{SecureRandom.hex}" } 5 | 6 | resource_type { :contact } 7 | 8 | to_create do |tag| 9 | client.tags.create(tag) 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /spec/factories/task.rb: -------------------------------------------------------------------------------- 1 | FactoryBot.define do 2 | factory :task, class: BaseCRM::Task do 3 | 4 | content { "Contact Tom" } 5 | due_date { "2014-09-27T16:32:56+00:00" } 6 | remind_at { "2014-09-29T15:32:56+00:00" } 7 | 8 | resource_id { contact.id } 9 | resource_type { :contact } 10 | 11 | to_create do |task| 12 | client.tasks.create(task) 13 | end 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /spec/factories/text_message.rb: -------------------------------------------------------------------------------- 1 | FactoryBot.define do 2 | factory :text_message, class: BaseCRM::TextMessage do 3 | 4 | 5 | 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /spec/http_client_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe BaseCRM::HttpClient do 4 | describe 'Retries' do 5 | let(:statuses_to_retry) { [503] } 6 | let(:max_retry) { 3 } 7 | subject(:client_with_retry) { client_with_basic_retry(max_retry: max_retry, on_statuses: statuses_to_retry) } 8 | 9 | it "should pass retry statues to Faraday and do a valid request" do 10 | expect(client_with_retry.http_client.client.app.options.retry_statuses).to match_array(statuses_to_retry) 11 | expect(client_with_retry.http_client.client.app.options.max).to eq(max_retry) 12 | expect(client_with_retry.accounts.self).to be_instance_of BaseCRM::Account 13 | end 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /spec/middlewares/raise_error_spec.rb: -------------------------------------------------------------------------------- 1 | require "spec_helper" 2 | 3 | describe BaseCRM::Middlewares::RaiseError do 4 | before { @raise_error = BaseCRM::Middlewares::RaiseError.new } 5 | 6 | describe :on_complete do 7 | 8 | it "returns nil when code 200..300" do 9 | expect { @raise_error.on_complete({:status => 204}) }.not_to raise_error 10 | end 11 | 12 | it "raises ResourceError when code 422 and no content type" do 13 | expect { @raise_error.on_complete({:status => 422, :response_headers => {}}) } 14 | .to raise_error do |error| 15 | expect(error).to be_a(BaseCRM::ResourceError) 16 | expect(error.code).to eql(422) 17 | expect(error.message).to eql("Unknown error occurred.") 18 | end 19 | end 20 | 21 | it "raises RequestError when code 400..500 and no content type" do 22 | expect { @raise_error.on_complete({:status => 400, :response_headers => {}}) } 23 | .to raise_error do |error| 24 | expect(error).to be_a(BaseCRM::RequestError) 25 | expect(error.code).to eql(400) 26 | expect(error.message).to eql("Unknown error occurred.") 27 | end 28 | end 29 | 30 | it "raises ServerError when code 500..600 and no content type" do 31 | expect { @raise_error.on_complete({:status => 500, :response_headers => {}}) } 32 | .to raise_error do |error| 33 | expect(error).to be_a(BaseCRM::ServerError) 34 | expect(error.code).to eql(500) 35 | expect(error.message).to eql("Unknown error occurred.") 36 | end 37 | end 38 | 39 | it "raises ResourceError when code 422 and XML (not supported) content type" do 40 | expect { @raise_error.on_complete({:status => 422, :response_headers => {'content-type' => "application/xml"}}) } 41 | .to raise_error do |error| 42 | expect(error).to be_a(BaseCRM::ResourceError) 43 | expect(error.code).to eql(422) 44 | expect(error.message).to eql("Unknown error occurred.") 45 | end 46 | end 47 | end 48 | end 49 | -------------------------------------------------------------------------------- /spec/models/sync_meta_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe BaseCRM::SyncMeta do 4 | describe 'Responds to' do 5 | it { should respond_to :ack } 6 | it { should respond_to :nack } 7 | it { should respond_to :acknowledged? } 8 | end 9 | 10 | describe :ack do 11 | subject { BaseCRM::SyncMeta } 12 | 13 | it 'returns array' do 14 | expect(subject.new.ack).to be_an Array 15 | end 16 | 17 | it 'returns two elements array' do 18 | expect(subject.new(ack_key: "123").ack).to eq([:ack, "123"]) 19 | end 20 | end 21 | 22 | describe :nack do 23 | subject { BaseCRM::SyncMeta } 24 | 25 | it 'returns array' do 26 | expect(subject.new.nack).to be_an Array 27 | end 28 | 29 | it 'returns two elements array' do 30 | expect(subject.new(ack_key: "123").nack).to eq([:nack, "123"]) 31 | end 32 | end 33 | 34 | describe :acknowledged? do 35 | subject { BaseCRM::SyncMeta } 36 | 37 | context 'neither ack nor nack method called' do 38 | it 'return false value' do 39 | expect(subject.new.acknowledged?).to eq(false) 40 | end 41 | end 42 | 43 | context 'ack method called' do 44 | it 'return true value' do 45 | ack_meta = subject.new 46 | ack_meta.ack 47 | expect(ack_meta.acknowledged?).to eq(true) 48 | end 49 | end 50 | 51 | context 'nack method called' do 52 | it 'return true value' do 53 | ack_meta = subject.new 54 | ack_meta.nack 55 | expect(ack_meta.acknowledged?).to eq(true) 56 | end 57 | end 58 | end 59 | end 60 | -------------------------------------------------------------------------------- /spec/services/accounts_service_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe BaseCRM::AccountsService do 4 | describe 'Responds to' do 5 | subject { client.accounts } 6 | 7 | it { should respond_to :self } 8 | end 9 | 10 | describe :self do 11 | it "returns instance of Account class" do 12 | expect(client.accounts.self).to be_instance_of BaseCRM::Account 13 | end 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /spec/services/associated_contacts_service_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe BaseCRM::AssociatedContactsService do 4 | describe 'Responds to' do 5 | subject { client.associated_contacts } 6 | 7 | it { should respond_to :all } 8 | it { should respond_to :create } 9 | it { should respond_to :destroy } 10 | it { should respond_to :where } 11 | end 12 | 13 | describe :all do 14 | it "returns a PaginatedResource" do 15 | deal_id = create(:deal).id 16 | expect(client.associated_contacts.all(deal_id)).to be_instance_of BaseCRM::PaginatedResource 17 | end 18 | end 19 | 20 | describe :where do 21 | it "returns an array" do 22 | deal_id = create(:deal).id 23 | expect(client.associated_contacts.where(deal_id, page: 1)).to be_an Array 24 | end 25 | end 26 | 27 | describe :create do 28 | it "returns instance of AssociatedContact class" do 29 | deal_id = create(:deal).id 30 | @associated_contact = build(:associated_contact) 31 | expect(client.associated_contacts.create(deal_id, @associated_contact)).to be_instance_of BaseCRM::AssociatedContact 32 | end 33 | end 34 | 35 | describe :destroy do 36 | it "returns true on success" do 37 | deal_id = create(:deal).id 38 | @associated_contact = create(:associated_contact, deal_id: deal_id) 39 | expect(client.associated_contacts.destroy(deal_id, @associated_contact.contact_id)).to be_truthy 40 | end 41 | end 42 | end 43 | -------------------------------------------------------------------------------- /spec/services/call_outcomes_service_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe BaseCRM::CallOutcomesService do 4 | describe 'Responds to' do 5 | subject { client.call_outcomes } 6 | 7 | it { should respond_to :all } 8 | it { should respond_to :where } 9 | end 10 | 11 | describe :all do 12 | it "returns a PaginatedResource" do 13 | expect(client.call_outcomes.all()).to be_instance_of BaseCRM::PaginatedResource 14 | end 15 | end 16 | 17 | describe :where do 18 | it "returns an array" do 19 | expect(client.call_outcomes.where(page: 1)).to be_an Array 20 | end 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /spec/services/calls_service_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe BaseCRM::CallsService do 4 | describe 'Responds to' do 5 | subject { client.calls } 6 | 7 | it { should respond_to :all } 8 | it { should respond_to :create } 9 | it { should respond_to :destroy } 10 | it { should respond_to :find } 11 | it { should respond_to :update } 12 | it { should respond_to :where } 13 | end 14 | 15 | describe :all do 16 | it "returns a PaginatedResource" do 17 | expect(client.calls.all()).to be_instance_of BaseCRM::PaginatedResource 18 | end 19 | end 20 | 21 | describe :where do 22 | it "returns an array" do 23 | expect(client.calls.where(page: 1)).to be_an Array 24 | end 25 | end 26 | 27 | describe :create do 28 | it "returns instance of Call class" do 29 | @call = build(:call) 30 | expect(client.calls.create(@call)).to be_instance_of BaseCRM::Call 31 | end 32 | end 33 | 34 | describe :find do 35 | before :each do 36 | @call = create(:call) 37 | end 38 | 39 | it "returns an instance of Call class" do 40 | expect(client.calls.find(@call.id)).to be_instance_of BaseCRM::Call 41 | end 42 | end 43 | 44 | describe :update do 45 | it "returns an updated instance of Call class" do 46 | @call = create(:call) 47 | contact = create(:contact) 48 | 49 | expect(client.calls.update(id: @call.id, resource_type: "contact", resource_id: contact.id)).to be_instance_of BaseCRM::Call 50 | end 51 | end 52 | 53 | describe :destroy do 54 | it "returns true on success" do 55 | @call = create(:call) 56 | expect(client.calls.destroy(@call.id)).to be_truthy 57 | end 58 | end 59 | end 60 | -------------------------------------------------------------------------------- /spec/services/contacts_service_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe BaseCRM::ContactsService do 4 | describe 'Responds to' do 5 | subject { client.contacts } 6 | 7 | it { should respond_to :all } 8 | it { should respond_to :create } 9 | it { should respond_to :destroy } 10 | it { should respond_to :find } 11 | it { should respond_to :update } 12 | it { should respond_to :where } 13 | end 14 | 15 | describe :all do 16 | it "returns a PaginatedResource" do 17 | expect(client.contacts.all()).to be_instance_of BaseCRM::PaginatedResource 18 | end 19 | end 20 | 21 | describe :where do 22 | it "returns an array" do 23 | expect(client.contacts.where(page: 1)).to be_an Array 24 | end 25 | end 26 | 27 | describe :create do 28 | it "returns instance of Contact class" do 29 | @contact = build(:contact) 30 | expect(client.contacts.create(@contact)).to be_instance_of BaseCRM::Contact 31 | end 32 | end 33 | 34 | describe :find do 35 | before :each do 36 | @contact = create(:contact) 37 | end 38 | 39 | it "returns an instance of Contact class" do 40 | expect(client.contacts.find(@contact.id)).to be_instance_of BaseCRM::Contact 41 | end 42 | end 43 | 44 | describe :update do 45 | it "returns an updated instance of Contact class" do 46 | @contact = create(:contact) 47 | expect(client.contacts.update(@contact)).to be_instance_of BaseCRM::Contact 48 | end 49 | end 50 | 51 | describe :destroy do 52 | it "returns true on success" do 53 | @contact = create(:contact) 54 | expect(client.contacts.destroy(@contact.id)).to be_truthy 55 | end 56 | end 57 | end 58 | -------------------------------------------------------------------------------- /spec/services/deal_sources_service_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe BaseCRM::DealSourcesService do 4 | describe 'Responds to' do 5 | subject { client.deal_sources } 6 | 7 | it { should respond_to :all } 8 | it { should respond_to :create } 9 | it { should respond_to :destroy } 10 | it { should respond_to :find } 11 | it { should respond_to :update } 12 | it { should respond_to :where } 13 | end 14 | 15 | describe :all do 16 | it "returns a PaginatedResource" do 17 | expect(client.deal_sources.all()).to be_instance_of BaseCRM::PaginatedResource 18 | end 19 | end 20 | 21 | describe :where do 22 | it "returns an array" do 23 | expect(client.deal_sources.where(page: 1)).to be_an Array 24 | end 25 | end 26 | 27 | describe :create do 28 | it "returns instance of DealSource class" do 29 | @deal_source = build(:deal_source) 30 | expect(client.deal_sources.create(@deal_source)).to be_instance_of BaseCRM::DealSource 31 | end 32 | end 33 | 34 | describe :find do 35 | before :each do 36 | @deal_source = create(:deal_source) 37 | end 38 | 39 | it "returns an instance of DealSource class" do 40 | expect(client.deal_sources.find(@deal_source.id)).to be_instance_of BaseCRM::DealSource 41 | end 42 | end 43 | 44 | describe :update do 45 | it "returns an updated instance of DealSource class" do 46 | @deal_source = create(:deal_source) 47 | expect(client.deal_sources.update(@deal_source)).to be_instance_of BaseCRM::DealSource 48 | end 49 | end 50 | 51 | describe :destroy do 52 | it "returns true on success" do 53 | @deal_source = create(:deal_source) 54 | expect(client.deal_sources.destroy(@deal_source.id)).to be_truthy 55 | end 56 | end 57 | end 58 | -------------------------------------------------------------------------------- /spec/services/deal_unqualified_reasons_service_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe BaseCRM::DealUnqualifiedReasonsService do 4 | describe 'Responds to' do 5 | subject { client.deal_unqualified_reasons } 6 | 7 | it { should respond_to :all } 8 | it { should respond_to :create } 9 | it { should respond_to :destroy } 10 | it { should respond_to :find } 11 | it { should respond_to :update } 12 | it { should respond_to :where } 13 | end 14 | 15 | describe :all do 16 | it "returns a PaginatedResource" do 17 | expect(client.deal_unqualified_reasons.all()).to be_instance_of BaseCRM::PaginatedResource 18 | end 19 | end 20 | 21 | describe :where do 22 | it "returns an array" do 23 | expect(client.deal_unqualified_reasons.where(page: 1)).to be_an Array 24 | end 25 | end 26 | 27 | describe :create do 28 | it "returns instance of DealUnqualifiedReason class" do 29 | @deal_unqualified_reason = build(:deal_unqualified_reason) 30 | expect(client.deal_unqualified_reasons.create(@deal_unqualified_reason)).to be_instance_of BaseCRM::DealUnqualifiedReason 31 | end 32 | end 33 | 34 | describe :find do 35 | before :each do 36 | @deal_unqualified_reason = create(:deal_unqualified_reason) 37 | end 38 | 39 | it "returns an instance of DealUnqualifiedReason class" do 40 | expect(client.deal_unqualified_reasons.find(@deal_unqualified_reason.id)).to be_instance_of BaseCRM::DealUnqualifiedReason 41 | end 42 | end 43 | 44 | describe :update do 45 | it "returns an updated instance of DealUnqualifiedReason class" do 46 | @deal_unqualified_reason = create(:deal_unqualified_reason) 47 | expect(client.deal_unqualified_reasons.update(@deal_unqualified_reason)).to be_instance_of BaseCRM::DealUnqualifiedReason 48 | end 49 | end 50 | 51 | describe :destroy do 52 | it "returns true on success" do 53 | @deal_unqualified_reason = create(:deal_unqualified_reason) 54 | expect(client.deal_unqualified_reasons.destroy(@deal_unqualified_reason.id)).to be_truthy 55 | end 56 | end 57 | end 58 | -------------------------------------------------------------------------------- /spec/services/deals_service_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe BaseCRM::DealsService do 4 | describe 'Responds to' do 5 | subject { client.deals } 6 | 7 | it { should respond_to :all } 8 | it { should respond_to :create } 9 | it { should respond_to :destroy } 10 | it { should respond_to :find } 11 | it { should respond_to :update } 12 | it { should respond_to :where } 13 | 14 | end 15 | 16 | describe :all do 17 | it "returns a PaginatedResource" do 18 | expect(client.deals.all()).to be_instance_of BaseCRM::PaginatedResource 19 | end 20 | end 21 | 22 | describe :where do 23 | it "returns an array" do 24 | expect(client.deals.where(page: 1)).to be_an Array 25 | end 26 | end 27 | 28 | describe :create do 29 | it "returns instance of Deal class" do 30 | deal = build(:deal) 31 | expect(client.deals.create(deal)).to be_instance_of BaseCRM::Deal 32 | end 33 | 34 | it "allows to create a Deal with hash of parameters" do 35 | deal = attributes_for(:deal) 36 | expect(client.deals.create(deal)).to be_instance_of BaseCRM::Deal 37 | end 38 | end 39 | 40 | describe :find do 41 | before :each do 42 | @deal = create(:deal) 43 | end 44 | 45 | it "returns an instance of Deal class" do 46 | expect(client.deals.find(@deal.id)).to be_instance_of BaseCRM::Deal 47 | end 48 | end 49 | 50 | describe :update do 51 | it "returns an updated instance of Deal class" do 52 | @deal = create(:deal) 53 | expect(client.deals.update(@deal)).to be_instance_of BaseCRM::Deal 54 | end 55 | 56 | it "allows to skip deal value in payload" do 57 | @deal = create(:deal, value: nil) 58 | expect(client.deals.update(@deal)).to be_instance_of BaseCRM::Deal 59 | end 60 | end 61 | 62 | describe :destroy do 63 | it "returns true on success" do 64 | @deal = create(:deal) 65 | expect(client.deals.destroy(@deal.id)).to be_truthy 66 | end 67 | end 68 | end 69 | -------------------------------------------------------------------------------- /spec/services/lead_sources_service_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe BaseCRM::LeadSourcesService do 4 | describe 'Responds to' do 5 | subject { client.lead_sources } 6 | 7 | it { should respond_to :all } 8 | it { should respond_to :create } 9 | it { should respond_to :destroy } 10 | it { should respond_to :find } 11 | it { should respond_to :update } 12 | it { should respond_to :where } 13 | end 14 | 15 | describe :all do 16 | it "returns a PaginatedResource" do 17 | expect(client.lead_sources.all()).to be_instance_of BaseCRM::PaginatedResource 18 | end 19 | end 20 | 21 | describe :where do 22 | it "returns an array" do 23 | expect(client.lead_sources.where(page: 1)).to be_an Array 24 | end 25 | end 26 | 27 | describe :create do 28 | it "returns instance of LeadSource class" do 29 | @lead_source = build(:lead_source) 30 | expect(client.lead_sources.create(@lead_source)).to be_instance_of BaseCRM::LeadSource 31 | end 32 | end 33 | 34 | describe :find do 35 | before :each do 36 | @lead_source = create(:lead_source) 37 | end 38 | 39 | it "returns an instance of LeadSource class" do 40 | expect(client.lead_sources.find(@lead_source.id)).to be_instance_of BaseCRM::LeadSource 41 | end 42 | end 43 | 44 | describe :update do 45 | it "returns an updated instance of LeadSource class" do 46 | @lead_source = create(:lead_source) 47 | expect(client.lead_sources.update(@lead_source)).to be_instance_of BaseCRM::LeadSource 48 | end 49 | end 50 | 51 | describe :destroy do 52 | it "returns true on success" do 53 | @lead_source = create(:lead_source) 54 | expect(client.lead_sources.destroy(@lead_source.id)).to be_truthy 55 | end 56 | end 57 | end 58 | -------------------------------------------------------------------------------- /spec/services/lead_unqualified_reasons_service_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe BaseCRM::LeadUnqualifiedReasonsService do 4 | describe 'Responds to' do 5 | subject { client.lead_unqualified_reasons } 6 | 7 | it { should respond_to :all } 8 | it { should respond_to :where } 9 | end 10 | 11 | describe :all do 12 | it "returns a PaginatedResource" do 13 | expect(client.lead_unqualified_reasons.all()).to be_instance_of BaseCRM::PaginatedResource 14 | end 15 | end 16 | 17 | describe :where do 18 | it "returns an array" do 19 | expect(client.lead_unqualified_reasons.where(page: 1)).to be_an Array 20 | end 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /spec/services/leads_service_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe BaseCRM::LeadsService do 4 | describe 'Responds to' do 5 | subject { client.leads } 6 | 7 | it { should respond_to :all } 8 | it { should respond_to :create } 9 | it { should respond_to :destroy } 10 | it { should respond_to :find } 11 | it { should respond_to :update } 12 | it { should respond_to :where } 13 | end 14 | 15 | describe :all do 16 | it "returns a PaginatedResource" do 17 | expect(client.leads.all()).to be_instance_of BaseCRM::PaginatedResource 18 | end 19 | end 20 | 21 | describe :where do 22 | it "returns an array" do 23 | expect(client.leads.where(page: 1)).to be_an Array 24 | end 25 | end 26 | 27 | describe :create do 28 | it "returns instance of Lead class" do 29 | @lead = build(:lead) 30 | expect(client.leads.create(@lead)).to be_instance_of BaseCRM::Lead 31 | end 32 | end 33 | 34 | describe :find do 35 | before :each do 36 | @lead = create(:lead) 37 | end 38 | 39 | it "returns an instance of Lead class" do 40 | expect(client.leads.find(@lead.id)).to be_instance_of BaseCRM::Lead 41 | end 42 | end 43 | 44 | describe :update do 45 | it "returns an updated instance of Lead class" do 46 | @lead = create(:lead) 47 | expect(client.leads.update(@lead)).to be_instance_of BaseCRM::Lead 48 | end 49 | end 50 | 51 | describe :destroy do 52 | it "returns true on success" do 53 | @lead = create(:lead) 54 | expect(client.leads.destroy(@lead.id)).to be_truthy 55 | end 56 | end 57 | end 58 | -------------------------------------------------------------------------------- /spec/services/line_items_service_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe BaseCRM::LineItemsService do 4 | before(:all) do 5 | @product = create(:product) 6 | @order = create_order 7 | end 8 | describe 'Responds to' do 9 | subject { client.line_items } 10 | 11 | it { should respond_to :all } 12 | it { should respond_to :create } 13 | it { should respond_to :destroy } 14 | it { should respond_to :find } 15 | it { should respond_to :where } 16 | end 17 | 18 | describe :all do 19 | it "returns a PaginatedResource" do 20 | order_id = create_order.id 21 | expect(client.line_items.all(order_id)).to be_instance_of BaseCRM::PaginatedResource 22 | end 23 | end 24 | 25 | describe :where do 26 | it "returns an array" do 27 | order_id = create_order.id 28 | expect(client.line_items.where(order_id, page: 1)).to be_an Array 29 | end 30 | end 31 | 32 | describe :create do 33 | it "returns instance of LineItem class" do 34 | order_id = create_order.id 35 | @line_item = build(:line_item, product_id: @product.id, order_id: @order.id) 36 | expect(client.line_items.create(order_id, @line_item)).to be_instance_of BaseCRM::LineItem 37 | end 38 | end 39 | 40 | describe :find do 41 | before :each do 42 | @line_item = create(:line_item, product_id: @product.id, order_id: @order.id) 43 | end 44 | 45 | it "returns an instance of LineItem class" do 46 | expect(client.line_items.find(@order.id, @line_item.id)).to be_instance_of BaseCRM::LineItem 47 | end 48 | end 49 | 50 | describe :destroy do 51 | it "returns true on success" do 52 | @line_item = create(:line_item, product_id: @product.id, order_id: @order.id) 53 | expect(client.line_items.destroy(@order.id, @line_item.id)).to be_truthy 54 | end 55 | end 56 | 57 | def create_order 58 | deal = create(:deal) 59 | create(:order, deal_id: deal.id) 60 | end 61 | end 62 | -------------------------------------------------------------------------------- /spec/services/loss_reasons_service_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe BaseCRM::LossReasonsService do 4 | describe 'Responds to' do 5 | subject { client.loss_reasons } 6 | 7 | it { should respond_to :all } 8 | it { should respond_to :create } 9 | it { should respond_to :destroy } 10 | it { should respond_to :find } 11 | it { should respond_to :update } 12 | it { should respond_to :where } 13 | end 14 | 15 | describe :all do 16 | it "returns a PaginatedResource" do 17 | expect(client.loss_reasons.all()).to be_instance_of BaseCRM::PaginatedResource 18 | end 19 | end 20 | 21 | describe :where do 22 | it "returns an array" do 23 | expect(client.loss_reasons.where(page: 1)).to be_an Array 24 | end 25 | end 26 | 27 | describe :create do 28 | it "returns instance of LossReason class" do 29 | @loss_reason = build(:loss_reason) 30 | expect(client.loss_reasons.create(@loss_reason)).to be_instance_of BaseCRM::LossReason 31 | end 32 | end 33 | 34 | describe :find do 35 | before :each do 36 | @loss_reason = create(:loss_reason) 37 | end 38 | 39 | it "returns an instance of LossReason class" do 40 | expect(client.loss_reasons.find(@loss_reason.id)).to be_instance_of BaseCRM::LossReason 41 | end 42 | end 43 | 44 | describe :update do 45 | it "returns an updated instance of LossReason class" do 46 | @loss_reason = create(:loss_reason) 47 | expect(client.loss_reasons.update(@loss_reason)).to be_instance_of BaseCRM::LossReason 48 | end 49 | end 50 | 51 | describe :destroy do 52 | it "returns true on success" do 53 | @loss_reason = create(:loss_reason) 54 | expect(client.loss_reasons.destroy(@loss_reason.id)).to be_truthy 55 | end 56 | end 57 | end 58 | -------------------------------------------------------------------------------- /spec/services/notes_service_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe BaseCRM::NotesService do 4 | describe 'Responds to' do 5 | subject { client.notes } 6 | 7 | it { should respond_to :all } 8 | it { should respond_to :create } 9 | it { should respond_to :destroy } 10 | it { should respond_to :find } 11 | it { should respond_to :update } 12 | it { should respond_to :where } 13 | end 14 | 15 | describe :all do 16 | it "returns a PaginatedResource" do 17 | expect(client.notes.all()).to be_instance_of BaseCRM::PaginatedResource 18 | end 19 | end 20 | 21 | describe :where do 22 | it "returns an array" do 23 | expect(client.notes.where(page: 1)).to be_an Array 24 | end 25 | end 26 | 27 | describe :create do 28 | it "returns instance of Note class" do 29 | @note = build(:note) 30 | expect(client.notes.create(@note)).to be_instance_of BaseCRM::Note 31 | end 32 | end 33 | 34 | describe :find do 35 | before :each do 36 | @note = create(:note) 37 | end 38 | 39 | it "returns an instance of Note class" do 40 | expect(client.notes.find(@note.id)).to be_instance_of BaseCRM::Note 41 | end 42 | end 43 | 44 | describe :update do 45 | it "returns an updated instance of Note class" do 46 | @note = create(:note) 47 | expect(client.notes.update(@note)).to be_instance_of BaseCRM::Note 48 | end 49 | end 50 | 51 | describe :destroy do 52 | it "returns true on success" do 53 | @note = create(:note) 54 | expect(client.notes.destroy(@note.id)).to be_truthy 55 | end 56 | end 57 | end 58 | -------------------------------------------------------------------------------- /spec/services/orders_service_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe BaseCRM::OrdersService do 4 | describe 'Responds to' do 5 | subject { client.orders } 6 | 7 | it { should respond_to :all } 8 | it { should respond_to :create } 9 | it { should respond_to :destroy } 10 | it { should respond_to :find } 11 | it { should respond_to :update } 12 | it { should respond_to :where } 13 | end 14 | 15 | describe :all do 16 | it "returns a PaginatedResource" do 17 | expect(client.orders.all()).to be_instance_of BaseCRM::PaginatedResource 18 | end 19 | end 20 | 21 | describe :where do 22 | it "returns an array" do 23 | expect(client.orders.where(page: 1)).to be_an Array 24 | end 25 | end 26 | 27 | describe :create do 28 | it "returns instance of Order class" do 29 | deal_id = create(:deal).id 30 | @order = build(:order, deal_id: deal_id) 31 | expect(client.orders.create(@order)).to be_instance_of BaseCRM::Order 32 | end 33 | end 34 | 35 | describe :find do 36 | before :each do 37 | @order = create_order 38 | end 39 | 40 | it "returns an instance of Order class" do 41 | expect(client.orders.find(@order.id)).to be_instance_of BaseCRM::Order 42 | end 43 | end 44 | 45 | describe :update do 46 | it "returns an updated instance of Order class" do 47 | @order = create_order 48 | expect(client.orders.update(@order)).to be_instance_of BaseCRM::Order 49 | end 50 | end 51 | 52 | describe :destroy do 53 | it "returns true on success" do 54 | @order = create_order 55 | expect(client.orders.destroy(@order.id)).to be_truthy 56 | end 57 | end 58 | 59 | def create_order 60 | deal = create(:deal) 61 | create(:order, deal_id: deal.id) 62 | end 63 | end 64 | -------------------------------------------------------------------------------- /spec/services/pipelines_service_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe BaseCRM::PipelinesService do 4 | describe 'Responds to' do 5 | subject { client.pipelines } 6 | 7 | it { should respond_to :all } 8 | it { should respond_to :where } 9 | end 10 | 11 | describe :all do 12 | it "returns a PaginatedResource" do 13 | expect(client.pipelines.all()).to be_instance_of BaseCRM::PaginatedResource 14 | end 15 | end 16 | 17 | describe :where do 18 | it "returns an array" do 19 | expect(client.pipelines.where(page: 1)).to be_an Array 20 | end 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /spec/services/products_service_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe BaseCRM::ProductsService do 4 | describe 'Responds to' do 5 | subject { client.products } 6 | 7 | it { should respond_to :all } 8 | it { should respond_to :create } 9 | it { should respond_to :destroy } 10 | it { should respond_to :find } 11 | it { should respond_to :update } 12 | it { should respond_to :where } 13 | end 14 | 15 | describe :all do 16 | it "returns a PaginatedResource" do 17 | expect(client.products.all()).to be_instance_of BaseCRM::PaginatedResource 18 | end 19 | end 20 | 21 | describe :where do 22 | it "returns an array" do 23 | expect(client.products.where(page: 1)).to be_an Array 24 | end 25 | end 26 | 27 | describe :create do 28 | it "returns instance of Product class" do 29 | @product = build(:product) 30 | expect(client.products.create(@product)).to be_instance_of BaseCRM::Product 31 | end 32 | end 33 | 34 | describe :find do 35 | before :each do 36 | @product = create(:product) 37 | end 38 | 39 | it "returns an instance of Product class" do 40 | expect(client.products.find(@product.id)).to be_instance_of BaseCRM::Product 41 | end 42 | end 43 | 44 | describe :update do 45 | it "returns an updated instance of Product class" do 46 | @product = create(:product) 47 | expect(client.products.update(@product)).to be_instance_of BaseCRM::Product 48 | end 49 | end 50 | 51 | describe :destroy do 52 | it "returns true on success" do 53 | @product = create(:product) 54 | expect(client.products.destroy(@product.id)).to be_truthy 55 | end 56 | end 57 | end 58 | -------------------------------------------------------------------------------- /spec/services/sources_service_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe BaseCRM::SourcesService do 4 | describe 'Responds to' do 5 | subject { client.sources } 6 | 7 | it { should respond_to :all } 8 | it { should respond_to :create } 9 | it { should respond_to :destroy } 10 | it { should respond_to :find } 11 | it { should respond_to :update } 12 | it { should respond_to :where } 13 | end 14 | 15 | describe :all do 16 | it "returns a PaginatedResource" do 17 | expect(client.sources.all()).to be_instance_of BaseCRM::PaginatedResource 18 | end 19 | end 20 | 21 | describe :where do 22 | it "returns an array" do 23 | expect(client.sources.where(page: 1)).to be_an Array 24 | end 25 | end 26 | 27 | describe :create do 28 | it "returns instance of Source class" do 29 | @source = build(:source) 30 | expect(client.sources.create(@source)).to be_instance_of BaseCRM::Source 31 | end 32 | end 33 | 34 | describe :find do 35 | before :each do 36 | @source = create(:source) 37 | end 38 | 39 | it "returns an instance of Source class" do 40 | expect(client.sources.find(@source.id)).to be_instance_of BaseCRM::Source 41 | end 42 | end 43 | 44 | describe :update do 45 | it "returns an updated instance of Source class" do 46 | @source = create(:source) 47 | expect(client.sources.update(@source)).to be_instance_of BaseCRM::Source 48 | end 49 | end 50 | 51 | describe :destroy do 52 | it "returns true on success" do 53 | @source = create(:source) 54 | expect(client.sources.destroy(@source.id)).to be_truthy 55 | end 56 | end 57 | end 58 | -------------------------------------------------------------------------------- /spec/services/stages_service_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe BaseCRM::StagesService do 4 | describe 'Responds to' do 5 | subject { client.stages } 6 | 7 | it { should respond_to :all } 8 | it { should respond_to :where } 9 | end 10 | 11 | describe :all do 12 | it "returns a PaginatedResource" do 13 | expect(client.stages.all()).to be_instance_of BaseCRM::PaginatedResource 14 | end 15 | end 16 | 17 | describe :where do 18 | it "returns an array" do 19 | expect(client.stages.where(page: 1)).to be_an Array 20 | end 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /spec/services/tags_service_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe BaseCRM::TagsService do 4 | describe 'Responds to' do 5 | subject { client.tags } 6 | 7 | it { should respond_to :all } 8 | it { should respond_to :create } 9 | it { should respond_to :destroy } 10 | it { should respond_to :find } 11 | it { should respond_to :update } 12 | it { should respond_to :where } 13 | end 14 | 15 | describe :all do 16 | it "returns a PaginatedResource" do 17 | expect(client.tags.all()).to be_instance_of BaseCRM::PaginatedResource 18 | end 19 | end 20 | 21 | describe :where do 22 | it "returns an array" do 23 | expect(client.tags.where(page: 1)).to be_an Array 24 | end 25 | end 26 | 27 | describe :create do 28 | it "returns instance of Tag class" do 29 | @tag = build(:tag) 30 | expect(client.tags.create(@tag)).to be_instance_of BaseCRM::Tag 31 | end 32 | end 33 | 34 | describe :find do 35 | before :each do 36 | @tag = create(:tag) 37 | end 38 | 39 | it "returns an instance of Tag class" do 40 | expect(client.tags.find(@tag.id)).to be_instance_of BaseCRM::Tag 41 | end 42 | end 43 | 44 | describe :update do 45 | it "returns an updated instance of Tag class" do 46 | @tag = create(:tag) 47 | expect(client.tags.update(@tag)).to be_instance_of BaseCRM::Tag 48 | end 49 | end 50 | 51 | describe :destroy do 52 | it "returns true on success" do 53 | @tag = create(:tag) 54 | expect(client.tags.destroy(@tag.id)).to be_truthy 55 | end 56 | end 57 | end 58 | -------------------------------------------------------------------------------- /spec/services/tasks_service_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe BaseCRM::TasksService do 4 | describe 'Responds to' do 5 | subject { client.tasks } 6 | 7 | it { should respond_to :all } 8 | it { should respond_to :create } 9 | it { should respond_to :destroy } 10 | it { should respond_to :find } 11 | it { should respond_to :update } 12 | it { should respond_to :where } 13 | end 14 | 15 | describe :all do 16 | it "returns a PaginatedResource" do 17 | expect(client.tasks.all()).to be_instance_of BaseCRM::PaginatedResource 18 | end 19 | end 20 | 21 | describe :where do 22 | it "returns an array" do 23 | expect(client.tasks.where(page: 1)).to be_an Array 24 | end 25 | end 26 | 27 | describe :create do 28 | it "returns instance of Task class" do 29 | @task = build(:task) 30 | expect(client.tasks.create(@task)).to be_instance_of BaseCRM::Task 31 | end 32 | end 33 | 34 | describe :find do 35 | before :each do 36 | @task = create(:task) 37 | end 38 | 39 | it "returns an instance of Task class" do 40 | expect(client.tasks.find(@task.id)).to be_instance_of BaseCRM::Task 41 | end 42 | end 43 | 44 | describe :update do 45 | it "returns an updated instance of Task class" do 46 | @task = create(:task) 47 | expect(client.tasks.update(@task)).to be_instance_of BaseCRM::Task 48 | end 49 | end 50 | 51 | describe :destroy do 52 | it "returns true on success" do 53 | @task = create(:task) 54 | expect(client.tasks.destroy(@task.id)).to be_truthy 55 | end 56 | end 57 | end 58 | -------------------------------------------------------------------------------- /spec/services/text_messages_service_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe BaseCRM::TextMessagesService do 4 | describe 'Responds to' do 5 | subject { client.text_messages } 6 | 7 | it { should respond_to :all } 8 | it { should respond_to :find } 9 | it { should respond_to :where } 10 | end 11 | 12 | describe :all do 13 | it "returns a PaginatedResource" do 14 | expect(client.text_messages.all()).to be_instance_of BaseCRM::PaginatedResource 15 | end 16 | end 17 | 18 | describe :where do 19 | it "returns an array" do 20 | expect(client.text_messages.where(page: 1)).to be_an Array 21 | end 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /spec/services/users_service_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe BaseCRM::UsersService do 4 | describe 'Responds to' do 5 | subject { client.users } 6 | 7 | it { should respond_to :all } 8 | it { should respond_to :find } 9 | it { should respond_to :self } 10 | it { should respond_to :where } 11 | end 12 | 13 | describe :all do 14 | it "returns a PaginatedResource" do 15 | expect(client.users.all()).to be_instance_of BaseCRM::PaginatedResource 16 | end 17 | end 18 | 19 | describe :where do 20 | it "returns an array" do 21 | expect(client.users.where(page: 1)).to be_an Array 22 | end 23 | end 24 | 25 | describe :find do 26 | it "returns an instance of User class" do 27 | user = client.users.self 28 | expect(client.users.find(user.id)).to be_instance_of BaseCRM::User 29 | end 30 | end 31 | 32 | describe :self do 33 | it "returns instance of User class" do 34 | expect(client.users.self).to be_instance_of BaseCRM::User 35 | end 36 | end 37 | end 38 | -------------------------------------------------------------------------------- /spec/services/visit_outcomes_service_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe BaseCRM::VisitOutcomesService do 4 | describe 'Responds to' do 5 | subject { client.visit_outcomes } 6 | 7 | it { should respond_to :all } 8 | it { should respond_to :where } 9 | end 10 | 11 | describe :all do 12 | it "returns a PaginatedResource" do 13 | expect(client.visit_outcomes.all()).to be_instance_of BaseCRM::PaginatedResource 14 | end 15 | end 16 | 17 | describe :where do 18 | it "returns an array" do 19 | expect(client.visit_outcomes.where(page: 1)).to be_an Array 20 | end 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /spec/services/visits_service_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe BaseCRM::VisitsService do 4 | describe 'Responds to' do 5 | subject { client.visits } 6 | 7 | it { should respond_to :all } 8 | it { should respond_to :where } 9 | end 10 | 11 | describe :all do 12 | it "returns a PaginatedResource" do 13 | expect(client.visits.all()).to be_instance_of BaseCRM::PaginatedResource 14 | end 15 | end 16 | 17 | describe :where do 18 | it "returns an array" do 19 | expect(client.visits.where(page: 1)).to be_an Array 20 | end 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require 'rspec/collection_matchers' 2 | require 'factory_bot' 3 | require 'faker' 4 | require 'securerandom' 5 | 6 | require 'basecrm' 7 | 8 | module FactoryBot 9 | module Strategy 10 | class Create 11 | def result(evaluation) 12 | evaluation.create(evaluation.object) 13 | end 14 | end 15 | end 16 | end 17 | 18 | Dir[File.join(__dir__, "/support/**/*.rb")].each { |f| require f } 19 | FactoryBot.find_definitions 20 | 21 | RSpec.configure do |config| 22 | config.include FactoryBot::Syntax::Methods 23 | 24 | config.expect_with :rspec do |expectations| 25 | # It makes the `description` and `failure_message` of custom matchers include text for helper methods 26 | expectations.include_chain_clauses_in_custom_matcher_descriptions = true 27 | end 28 | 29 | config.order = :random 30 | 31 | config.raise_errors_for_deprecations! 32 | end 33 | -------------------------------------------------------------------------------- /spec/support/client_helpers.rb: -------------------------------------------------------------------------------- 1 | module ClientHelpers 2 | def client 3 | @client ||= BaseCRM::Client.new(access_token: access_token, base_url: base_url) 4 | end 5 | 6 | def client_with_basic_retry(max_retry: 1, on_statuses: []) 7 | @client_with_basic_retry ||= BaseCRM::Client.new(access_token: access_token, base_url: base_url, max_retry: max_retry, retry_statuses: on_statuses) 8 | end 9 | 10 | def access_token 11 | @access_token ||= ENV.fetch("BASECRM_ACCESS_TOKEN") { raise '"BASECRM_ACCESS_TOKEN" has not been found.' } 12 | end 13 | 14 | def base_url 15 | @basecrm_url ||= ENV.fetch("BASECRM_BASE_URL") { "https://api.getbase.com" } 16 | end 17 | 18 | def contact 19 | @contact ||= FactoryBot.create(:contact) 20 | end 21 | end 22 | 23 | RSpec.configure do |config| 24 | include ClientHelpers 25 | end 26 | 27 | FactoryBot::SyntaxRunner.send(:include, ClientHelpers) 28 | -------------------------------------------------------------------------------- /spec/utils/coercion.rb: -------------------------------------------------------------------------------- 1 | require "spec_helper" 2 | 3 | describe BaseCRM::Coercion do 4 | describe "to_decimal" do 5 | it { expect(BaseCRM::Coercion.to_decimal_value(0)).to eql(0) } 6 | it { expect(BaseCRM::Coercion.to_decimal_value("0")).to eql(0) } 7 | it { expect(BaseCRM::Coercion.to_decimal_value(nil)).to eql(0) } 8 | it { expect(BaseCRM::Coercion.to_decimal_value(1.1)).to eql(BigDecimal("1.1", 15)) } 9 | it { expect(BaseCRM::Coercion.to_decimal_value("1.11")).to eql(BigDecimal("1.11", 15)) } 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /spec/utils/coercion_spec.rb: -------------------------------------------------------------------------------- 1 | require "bigdecimal" 2 | require "spec_helper" 3 | 4 | describe BaseCRM::Coercion do 5 | describe "to_decimal" do 6 | it { expect(BaseCRM::Coercion.to_decimal_value(0)).to eql(0) } 7 | it { expect(BaseCRM::Coercion.to_decimal_value("0")).to eql(0) } 8 | it { expect(BaseCRM::Coercion.to_decimal_value(nil)).to eql(0) } 9 | it { expect(BaseCRM::Coercion.to_decimal_value(1.1)).to eql(BigDecimal("1.1", 15)) } 10 | it { expect(BaseCRM::Coercion.to_decimal_value("1.11")).to eql(BigDecimal("1.11", 15)) } 11 | end 12 | 13 | describe "to_string" do 14 | it { expect(BaseCRM::Coercion.to_string(1)).to eql("1") } 15 | it { expect(BaseCRM::Coercion.to_string("1")).to eql("1") } 16 | it { expect(BaseCRM::Coercion.to_string(1.11)).to eql("1.11") } 17 | it { expect(BaseCRM::Coercion.to_string("1.11")).to eql("1.11") } 18 | it { expect(BaseCRM::Coercion.to_string(BigDecimal("1.11"))).to eql("1.11") } 19 | it { expect(BaseCRM::Coercion.to_string(BigDecimal(1.11, 15))).to eql("1.11") } 20 | end 21 | end 22 | --------------------------------------------------------------------------------