freshworks 1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 802d22c546e1a9067f154e1d54a68c66a7e61cb881cfb4d4bad8144899447a59
4
+ data.tar.gz: ec0d7692dce6f9aed56f2fc64385be71923d163cbd4632e591669392bdfe7aa4
5
+ SHA512:
6
+ metadata.gz: 0f9430cf1e6890bae90cd88f9fcc2eca2637b22d0dceeb7365c630a9ceaf93484703a2961beb0b2e4d8c4d6ea52ee3d64c659762539ef81e034a0748221f89c4
7
+ data.tar.gz: eea41fc28f5008720e298245114029ebf0ce843acd461af3b8a5faf288ab29f5b943004277f2e27f408de52a9a9ab309d2db13027e94578adb8aa95b3ac0971d
data/.gitignore ADDED
@@ -0,0 +1,40 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+ Gemfile.lock
13
+
14
+ ## Ignore RubyMine
15
+ .idea/
16
+ *.iml
17
+
18
+ ## Specific to RubyMotion:
19
+ .dat*
20
+ .repl_history
21
+ build/
22
+
23
+ ## Documentation cache and generated files:
24
+ /.yardoc/
25
+ /_yardoc/
26
+ /doc/
27
+ /rdoc/
28
+
29
+ ## Environment normalization:
30
+ /.bundle/
31
+ /vendor/bundle
32
+ /lib/bundler/man/
33
+
34
+ # for a library or gem, you might want to ignore these files since the code is
35
+ # intended to run in multiple environments; otherwise, check them in:
36
+ # .ruby-version
37
+ # .ruby-gemset
38
+
39
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
40
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.6.2
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at dev@bonus.ly. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in freshworks.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 markovAntony
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,86 @@
1
+ [api-docs]: https://apidocs.freshworks.com/
2
+ [free-sw]: https://www.fsf.org/licensing/essays/free-sw.html
3
+ [issues]: https://github.com/bonusly/freshworks/issues
4
+ [fork]: http://help.github.com/fork-a-repo/
5
+ [branch]: http://learn.github.com/p/branching.html
6
+ [pr]: http://help.github.com/send-pull-requests/
7
+
8
+ # Freshworks Gem
9
+ A Ruby interface for the [Freshworks Public API][api-docs].
10
+
11
+ ## Installation
12
+ ```Bash
13
+ gem install freshworks
14
+ ```
15
+
16
+ ## Examples
17
+ Significant functionality is covered with this gem, but some basic functionality is covered below.
18
+ If you're interested in learning more, it's probably easiest to explore the specs in `/spec/freshworks`.
19
+
20
+ Set up your keys:
21
+ ```Ruby
22
+ Freshworks.configure do |c|
23
+ c.account_api_key = 'ACCOUNT_API_KEY'
24
+ c.event_api_key = 'EVENT_API_KEY'
25
+ c.event_auth_key = 'EVENT_AUTH_KEY'
26
+ end
27
+ ```
28
+
29
+ Retrieve all accounts:
30
+ ```Ruby
31
+ Freshworks::Account.retrieve_all
32
+ ```
33
+
34
+ Retrieve a specific account:
35
+ ```Ruby
36
+ Freshworks::Account.retrieve('ACCOUNT_ID')
37
+ ```
38
+
39
+ Modify an account:
40
+ ```Ruby
41
+ account = Freshworks::Account.retrieve('ACCOUNT_ID')
42
+ account.name = 'TEST'
43
+
44
+ Freshworks::Account.modify('ACCOUNT_ID', account)
45
+ ```
46
+
47
+ Create an event:
48
+ ```Ruby
49
+ event = { id: 'test', name: 'Testing the API.'}
50
+ details = 'These details should be associated with the event in Freshworks'
51
+
52
+ Freshworks::Event.create(event, details)
53
+ ```
54
+
55
+ ## Contributing
56
+ In the spirit of [free software][free-sw], **everyone** is encouraged to help
57
+ improve this project. Here are some ways *you* can contribute:
58
+
59
+ * Report bugs.
60
+ * Suggest new features.
61
+ * Write or edit documentation.
62
+ * Write specifications.
63
+ * Write code (**no patch is too small**: fix typos, add comments, clean up inconsistent whitespace).
64
+ * Refactor code.
65
+ * Fix [issues][].
66
+
67
+ #### Submitting an issue:
68
+ We use the [GitHub issue tracker][issues] to track bugs and features. Before
69
+ submitting a bug report or feature request, check to make sure it hasn't
70
+ already been submitted. When submitting a bug report, please include a stack
71
+ trace and any details that may be necessary to reproduce
72
+ the bug, including your gem version, Ruby version, and operating system.
73
+ Ideally, a bug report should include a pull request with failing specs.
74
+
75
+ #### Submitting a Pull Request
76
+ 1. [Fork the repository.][fork]
77
+ 2. [Create a topic branch.][branch]
78
+ 3. Add specs for your unimplemented feature or bug fix.
79
+ 4. Run `bundle exec rake spec`. If your specs pass, return to step 3.
80
+ 5. Implement your feature or bug fix.
81
+ 6. Run `bundle exec rake spec`. If your specs fail, return to step 5.
82
+ 7. Add documentation for your feature or bug fix.
83
+ 8. Commit and push your changes.
84
+ 9. [Submit a pull request.][pr]
85
+
86
+ _(Shamelessly based on the [Twitter Gem](https://github.com/sferik/twitter))_
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ # run console with gem loaded
7
+ task :console do
8
+ exec "irb -r freshworks -I ./lib"
9
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "freshworks"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,100 @@
1
+ ---
2
+ Freshworks::Base:
3
+ source: ~
4
+ properties:
5
+
6
+ Freshworks::Account:
7
+ source: http://apidocs.freshworks.com/apidoc.html#Accounts
8
+ properties:
9
+ - account_id
10
+ - name
11
+ - join_date
12
+ - renewal_date
13
+ - billing_account_id
14
+ - support_account_id
15
+ - crm_account_id
16
+ - billing_street
17
+ - billing_city
18
+ - billing_postal_code
19
+ - billing_state
20
+ - billing_country
21
+ - phone
22
+ - employees
23
+ - industry
24
+ - tier
25
+ - csm_score
26
+ - current_nps_score
27
+ - sales_rep_name
28
+ - sales_rep_email
29
+ - source
30
+ - stage
31
+ - is_deleted
32
+ - is_churned
33
+ - inactive_time
34
+ - inactive_reason
35
+ - parent_account_id
36
+ - hierarchy_label
37
+ - is_leaf
38
+ - latest_status_title
39
+ - latest_status_details
40
+ - latest_status_date
41
+ - assigned_csms
42
+ - custom_label_dimensions
43
+ - custom_value_dimensions
44
+ - custom_event_dimensions
45
+ - stage_history
46
+ - nps_history
47
+
48
+ Freshworks::Event:
49
+ source: http://apidocs.freshworks.com/restapi.html
50
+ properties:
51
+ - account_id
52
+ - action
53
+ - active_duration
54
+ - created_at
55
+ - details
56
+ - feature
57
+ - module
58
+ - product
59
+ - session_id
60
+ - time_spent
61
+ - total
62
+ - user_id
63
+
64
+ Freshworks::Metric:
65
+ source: http://apidocs.freshworks.com/apidoc.html#Custom%20Metrics
66
+ properties:
67
+ - account_id
68
+ - name
69
+ - metrics
70
+ - direction
71
+ - page
72
+
73
+ Freshworks::User:
74
+ source: http://apidocs.freshworks.com/apidoc.html#Accounts%20Product%20Users
75
+ properties:
76
+ - user_id
77
+ - account_id
78
+ - first_name
79
+ - last_name
80
+ - contact_user_id
81
+ - phone
82
+ - mobile_phone
83
+ - email
84
+ - salutation
85
+ - title
86
+ - role
87
+ - department
88
+ - source
89
+ - mailing_street
90
+ - mailing_city
91
+ - mailing_state
92
+ - mailing_postal_code
93
+ - mailing_country
94
+ - lead_source
95
+ - product_join_date
96
+ - is_active
97
+ - custom_label_dimensions
98
+ - custom_value_dimensions
99
+ - custom_event_dimensions
100
+ ...
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'freshworks/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'freshworks'
8
+ spec.version = Freshworks::VERSION
9
+ spec.authors = ['Ellen Cornelius', 'Nowai Matthew', 'Andrew Brown', 'Robert Ingrum']
10
+ spec.email = 'dev@bonus.ly'
11
+ spec.summary = 'Wrapper for Freshworks API'
12
+ spec.description = 'Freshworks is customer success software used to reduce churn and increase B2B SaaS adoption.'
13
+ spec.homepage = 'http://bonus.ly'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = 'exe'
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'httparty', '~> 0.13'
22
+ spec.add_development_dependency 'bundler', '> 1.11'
23
+ spec.add_development_dependency 'rake', '~> 12.3.3'
24
+ spec.add_development_dependency 'rspec'
25
+ spec.add_development_dependency 'rack', '>= 2.0.8'
26
+ spec.add_development_dependency 'rspec-rails'
27
+ spec.add_development_dependency 'rails-html-sanitizer', '~> 1.0.4'
28
+ spec.add_development_dependency 'loofah', '>= 2.3.1'
29
+ spec.add_development_dependency 'nokogiri', '>= 1.10.9'
30
+ spec.add_development_dependency 'spring'
31
+ spec.add_development_dependency 'spring-commands-rspec'
32
+ spec.add_development_dependency 'spring-commands-cucumber'
33
+ end
data/lib/freshworks.rb ADDED
@@ -0,0 +1,56 @@
1
+ require 'httparty'
2
+ require 'json'
3
+
4
+ module Freshworks
5
+ class Configuration
6
+ attr_accessor :base_uri, :account_api_key, :event_api_key, :event_auth_key
7
+
8
+ def initialize
9
+ self.account_api_key = nil
10
+ self.event_api_key = nil
11
+ self.event_auth_key = nil
12
+ end
13
+ end
14
+
15
+ def self.configuration
16
+ @configuration ||= Configuration.new
17
+ end
18
+
19
+ def self.configure
20
+ yield(configuration) if block_given?
21
+ end
22
+
23
+ def self.full_endpoint_uri(base_uri, version_uri, *params)
24
+ base = self.uri(base_uri, version_uri)
25
+
26
+ params.flatten!
27
+ params.each { |param| base << '/' + param } unless params.empty?
28
+
29
+ base
30
+ end
31
+
32
+ def self.uri(base_uri, version_uri)
33
+ base_uri + version_uri
34
+ end
35
+
36
+ def self.api_key_uri
37
+ '?api_key=' + Freshworks.configuration.account_api_key
38
+ end
39
+
40
+ def self.to_records_json(objects)
41
+ "{\"records\": #{Array(objects).map(&:serialize)}}".to_s.delete('\\').gsub('"{', '{').gsub('}"', '}')
42
+ end
43
+
44
+ def self.gem_root
45
+ File.expand_path('../..', __FILE__)
46
+ end
47
+ end
48
+
49
+ require_relative 'freshworks/serializable'
50
+ require_relative 'freshworks/request_helper'
51
+ require_relative 'freshworks/base'
52
+ require_relative 'freshworks/user'
53
+ require_relative 'freshworks/account'
54
+ require_relative 'freshworks/event'
55
+ require_relative 'freshworks/response'
56
+ require_relative 'freshworks/metric'
@@ -0,0 +1,69 @@
1
+ class Freshworks::Account < Freshworks::Base
2
+ def self.retrieve_all
3
+ get
4
+ end
5
+
6
+ def self.retrieve(id)
7
+ get([id])
8
+ end
9
+
10
+ def self.bulk_insert_modify(accounts)
11
+ post([], json_data(Freshworks.to_records_json(accounts)))
12
+ end
13
+
14
+ def self.modify(id, account)
15
+ put([id], json_data(account.to_json))
16
+ end
17
+
18
+ def self.retrieve_custom_metrics(id)
19
+ get([id, 'metrics'])
20
+ end
21
+
22
+ def self.retrieve_invoice_statements(id)
23
+ get([id, 'statements'])
24
+ end
25
+
26
+ def self.retrieve_subscription_history(id)
27
+ get([id, 'subscriptions'])
28
+ end
29
+
30
+ def self.retrieve_support_tickets(id)
31
+ get([id, 'support_tickets'])
32
+ end
33
+
34
+ def self.retrieve_product_users(id)
35
+ get([id, 'users'])
36
+ end
37
+
38
+ def self.retrieve_contacts(id)
39
+ get([id, 'contacts'])
40
+ end
41
+
42
+ def self.deactivate_account(id)
43
+ delete([id])
44
+ end
45
+
46
+ def self.delete_stage_history(id, name, timestamp)
47
+ delete([id, 'stage_history', name, timestamp])
48
+ end
49
+
50
+ def self.delete_dimension_values(id, key)
51
+ delete([id, 'dimension_values', key])
52
+ end
53
+
54
+ def self.delete_dimension_labels(id, key)
55
+ delete([id, 'dimension_labels', key])
56
+ end
57
+
58
+ def self.delete_assigned_csm_reps(id, email)
59
+ delete([id, 'assigned_csms', email])
60
+ end
61
+
62
+ def self.delete_nps_history(id, timestamp)
63
+ delete([id, 'nps_history', timestamp])
64
+ end
65
+
66
+ def self.endpoint_path
67
+ ['accounts']
68
+ end
69
+ end
@@ -0,0 +1,73 @@
1
+ require 'active_support'
2
+ require 'active_support/core_ext'
3
+
4
+ class Freshworks::Base
5
+ include Serializable
6
+
7
+ BASE_URI = 'https://api-us.freshsuccess.com'
8
+ VERSION_URI = '/api/v2'
9
+
10
+ REQUIRED_PARAMS = []
11
+
12
+ attr_reader :raw_response
13
+
14
+ class << self
15
+ delegate :get, :post, :put, :delete, to: :request_helper, allow_nil: true
16
+ end
17
+
18
+ def self.endpoint(*params)
19
+ params = [endpoint_path, params, Freshworks.api_key_uri].flatten.compact.map(&:to_s)
20
+ Freshworks.full_endpoint_uri(BASE_URI, VERSION_URI, params)
21
+ end
22
+
23
+ def self.endpoint_path
24
+ raise NotImplementedError.new( 'This method needs to be overridden in a child class. Proper implementation '\
25
+ 'should return an array where each index contains a different part of the path. For example: '\
26
+ '[\'test\', \'best\'] becomes \'/test/best/\'.' )
27
+ end
28
+
29
+ def self.json_data(body)
30
+ { body: body, headers: json_headers }
31
+ end
32
+
33
+ def self.json_headers
34
+ { 'Content-Type': 'application/json' }
35
+ end
36
+
37
+ def self.request_helper
38
+ Freshworks::RequestHelper.new(self)
39
+ end
40
+
41
+ def initialize(params, raw_response = nil)
42
+ missing_params = REQUIRED_PARAMS - params.keys
43
+ raise ArgumentError.new("Missing required params #{missing_params.join(', ')}") unless missing_params.empty?
44
+
45
+ load_model_properties
46
+ clean_params(params)
47
+ populate_properties(params)
48
+
49
+ @raw_response = raw_response
50
+ end
51
+
52
+ def to_json
53
+ serialize
54
+ end
55
+
56
+ private
57
+
58
+ def load_model_properties
59
+ model_config[:properties].each { |prop| self.class.class_eval { attr_accessor prop.to_sym } }
60
+ end
61
+
62
+ def clean_params(params)
63
+ params.each { |_, value| value.gsub!(/"/, '') if value.respond_to?(:gsub!) }
64
+ end
65
+
66
+ def populate_properties(params)
67
+ params.each { |key, value| instance_variable_set("@#{key}", value) }
68
+ end
69
+
70
+ def model_config
71
+ YAML::load(File.read("#{Freshworks.gem_root}/config/model_properties.yml"))[self.class.name.to_s].with_indifferent_access
72
+ end
73
+ end
@@ -0,0 +1,48 @@
1
+ class Freshworks::Event < Freshworks::Base
2
+ BASE_URI = 'https://events-us.freshsuccess.com'
3
+ VERSION_URI = '/v1'
4
+
5
+ REQUIRED_PARAMS = %w{
6
+ account_id
7
+ user_id
8
+ created_at
9
+ session_id
10
+ }
11
+
12
+ def self.identify_user(event, details)
13
+ create(event, 'identifyUser', { details: details })
14
+ end
15
+
16
+ def self.identify_account(event, details)
17
+ create(event, 'identifyAccount', { details: details })
18
+ end
19
+
20
+ def self.session_sync(event, active_duration)
21
+ create(event, 'sessionSync', { active_duration: active_duration })
22
+ end
23
+
24
+ def self.module_end(event, module_name, time_spent)
25
+ create(event, 'moduleEnd', { module: module_name, time_spent: time_spent })
26
+ end
27
+
28
+ def self.feature(event, feature, module_name, total)
29
+ create(event, 'feature', { feature: feature, module: module_name, total: total })
30
+ end
31
+
32
+ def self.create(event, action, optional_fields={})
33
+ body = event.to_h
34
+ body.merge!({ action: action })
35
+ body.merge!(optional_fields)
36
+
37
+ post([], json_data(body))
38
+ end
39
+
40
+ def self.endpoint_path
41
+ [Freshworks.configuration.event_auth_key, Freshworks.configuration.event_api_key]
42
+ end
43
+
44
+ def self.endpoint(*params)
45
+ params = [endpoint_path, params].flatten.compact.map(&:to_s)
46
+ Freshworks.full_endpoint_uri(BASE_URI, VERSION_URI, params)
47
+ end
48
+ end
@@ -0,0 +1,21 @@
1
+ class Freshworks::Metric < Freshworks::Base
2
+ def self.retrieve(name)
3
+ get([name])
4
+ end
5
+
6
+ def self.bulk_insert_modify(metrics)
7
+ post([], json_data(Freshworks.to_records_json(metrics)))
8
+ end
9
+
10
+ def self.modify(name, metric)
11
+ put([name], json_data(metric.to_json))
12
+ end
13
+
14
+ def self.delete(name)
15
+ request_helper.delete([name])
16
+ end
17
+
18
+ def self.endpoint_path
19
+ ['metrics']
20
+ end
21
+ end
@@ -0,0 +1,31 @@
1
+ require 'httparty'
2
+
3
+ class Freshworks::RequestHelper
4
+ def get(path_params=[], data={})
5
+ request(:get, path_params, data)
6
+ end
7
+
8
+ def post(path_params=[], data={})
9
+ request(:post, path_params, data)
10
+ end
11
+
12
+ def put(path_params=[], data={})
13
+ request(:put, path_params, data)
14
+ end
15
+
16
+ def delete(path_params=[], data={})
17
+ request(:delete, path_params, data)
18
+ end
19
+
20
+ def request(method, path_params=[], data={})
21
+ parse_response(HTTParty.send(method, @model.endpoint(path_params), data))
22
+ end
23
+
24
+ def parse_response(raw_response)
25
+ Freshworks::Response.new(raw_response)
26
+ end
27
+
28
+ def initialize(model)
29
+ @model = model
30
+ end
31
+ end
@@ -0,0 +1,8 @@
1
+ class Freshworks::Response
2
+ attr_reader :parsed_response, :code
3
+
4
+ def initialize(raw_response)
5
+ @parsed_response = raw_response.parsed_response
6
+ @code = raw_response.code
7
+ end
8
+ end
@@ -0,0 +1,24 @@
1
+ module Serializable
2
+ @@serializer = JSON
3
+
4
+ def serialize
5
+ obj = {}
6
+ instance_variables.map do |var|
7
+ iv = instance_variable_get(var)
8
+ obj[var.to_s.gsub('@', '')] = iv unless iv.nil?
9
+ end
10
+
11
+ @@serializer.dump obj
12
+ end
13
+
14
+ def unserialize(string)
15
+ obj = @@serializer.parse(string)
16
+ obj.keys.each do |key|
17
+ instance_variable_set(key, obj[key])
18
+ end
19
+ end
20
+
21
+ def to_h
22
+ @@serializer.parse serialize
23
+ end
24
+ end
@@ -0,0 +1,25 @@
1
+ class Freshworks::User < Freshworks::Base
2
+ def self.retrieve_all
3
+ get
4
+ end
5
+
6
+ def self.retrieve(id, account_id=nil)
7
+ get([id, account_id])
8
+ end
9
+
10
+ def self.bulk_insert_modify(accounts)
11
+ post([], json_data(Freshworks.to_records_json(accounts)))
12
+ end
13
+
14
+ def self.modify(id, account)
15
+ put([id], json_data(account.to_json))
16
+ end
17
+
18
+ def self.deactivate(id, account_id=nil)
19
+ delete([id, account_id])
20
+ end
21
+
22
+ def self.endpoint_path
23
+ ['account_users']
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module Freshworks
2
+ VERSION = '1.0'
3
+ end
metadata ADDED
@@ -0,0 +1,236 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: freshworks
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ platform: ruby
6
+ authors:
7
+ - Ellen Cornelius
8
+ - Nowai Matthew
9
+ - Andrew Brown
10
+ - Robert Ingrum
11
+ autorequire:
12
+ bindir: exe
13
+ cert_chain: []
14
+ date: 2020-04-09 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: httparty
18
+ requirement: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - "~>"
21
+ - !ruby/object:Gem::Version
22
+ version: '0.13'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '0.13'
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">"
35
+ - !ruby/object:Gem::Version
36
+ version: '1.11'
37
+ type: :development
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">"
42
+ - !ruby/object:Gem::Version
43
+ version: '1.11'
44
+ - !ruby/object:Gem::Dependency
45
+ name: rake
46
+ requirement: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - "~>"
49
+ - !ruby/object:Gem::Version
50
+ version: 12.3.3
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: 12.3.3
58
+ - !ruby/object:Gem::Dependency
59
+ name: rspec
60
+ requirement: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ type: :development
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ - !ruby/object:Gem::Dependency
73
+ name: rack
74
+ requirement: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: 2.0.8
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: 2.0.8
86
+ - !ruby/object:Gem::Dependency
87
+ name: rspec-rails
88
+ requirement: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ type: :development
94
+ prerelease: false
95
+ version_requirements: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ - !ruby/object:Gem::Dependency
101
+ name: rails-html-sanitizer
102
+ requirement: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - "~>"
105
+ - !ruby/object:Gem::Version
106
+ version: 1.0.4
107
+ type: :development
108
+ prerelease: false
109
+ version_requirements: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - "~>"
112
+ - !ruby/object:Gem::Version
113
+ version: 1.0.4
114
+ - !ruby/object:Gem::Dependency
115
+ name: loofah
116
+ requirement: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: 2.3.1
121
+ type: :development
122
+ prerelease: false
123
+ version_requirements: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: 2.3.1
128
+ - !ruby/object:Gem::Dependency
129
+ name: nokogiri
130
+ requirement: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: 1.10.9
135
+ type: :development
136
+ prerelease: false
137
+ version_requirements: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: 1.10.9
142
+ - !ruby/object:Gem::Dependency
143
+ name: spring
144
+ requirement: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ type: :development
150
+ prerelease: false
151
+ version_requirements: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ - !ruby/object:Gem::Dependency
157
+ name: spring-commands-rspec
158
+ requirement: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ version: '0'
163
+ type: :development
164
+ prerelease: false
165
+ version_requirements: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - ">="
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ - !ruby/object:Gem::Dependency
171
+ name: spring-commands-cucumber
172
+ requirement: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - ">="
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
177
+ type: :development
178
+ prerelease: false
179
+ version_requirements: !ruby/object:Gem::Requirement
180
+ requirements:
181
+ - - ">="
182
+ - !ruby/object:Gem::Version
183
+ version: '0'
184
+ description: Freshworks is customer success software used to reduce churn and increase
185
+ B2B SaaS adoption.
186
+ email: dev@bonus.ly
187
+ executables: []
188
+ extensions: []
189
+ extra_rdoc_files: []
190
+ files:
191
+ - ".gitignore"
192
+ - ".rspec"
193
+ - ".ruby-version"
194
+ - CODE_OF_CONDUCT.md
195
+ - Gemfile
196
+ - LICENSE.txt
197
+ - README.md
198
+ - Rakefile
199
+ - bin/console
200
+ - bin/setup
201
+ - config/model_properties.yml
202
+ - freshworks.gemspec
203
+ - lib/freshworks.rb
204
+ - lib/freshworks/account.rb
205
+ - lib/freshworks/base.rb
206
+ - lib/freshworks/event.rb
207
+ - lib/freshworks/metric.rb
208
+ - lib/freshworks/request_helper.rb
209
+ - lib/freshworks/response.rb
210
+ - lib/freshworks/serializable.rb
211
+ - lib/freshworks/user.rb
212
+ - lib/freshworks/version.rb
213
+ homepage: http://bonus.ly
214
+ licenses:
215
+ - MIT
216
+ metadata: {}
217
+ post_install_message:
218
+ rdoc_options: []
219
+ require_paths:
220
+ - lib
221
+ required_ruby_version: !ruby/object:Gem::Requirement
222
+ requirements:
223
+ - - ">="
224
+ - !ruby/object:Gem::Version
225
+ version: '0'
226
+ required_rubygems_version: !ruby/object:Gem::Requirement
227
+ requirements:
228
+ - - ">="
229
+ - !ruby/object:Gem::Version
230
+ version: '0'
231
+ requirements: []
232
+ rubygems_version: 3.0.3
233
+ signing_key:
234
+ specification_version: 4
235
+ summary: Wrapper for Freshworks API
236
+ test_files: []