eloqua-api-client 0.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: 43430eda667393e9838d2058585aaf59236bdb9d49a6731918b153507c44ec7c
4
+ data.tar.gz: fe7035e1bb15335430ba657a867e5a5811be858611a85aa8fda2f9aba58248c6
5
+ SHA512:
6
+ metadata.gz: 62e022739bb2d07265a818272c9a460b0fffb1b7be5a26aa81df36c746ab257303329017c7cdcc29c55615ce3d74fd268d5e0362e7900c6a61a1cf992b1053d9
7
+ data.tar.gz: b6106c46559545e2885f4673888c0769d1e28f0b974b263e64226b104378ff7fd16a719f705bee7f29ac1d6487110a1856918bb18826eca3be615591ed050895
@@ -0,0 +1,15 @@
1
+ orbs:
2
+ ruby: circleci/ruby@1.2.0
3
+ version: 2.1
4
+ jobs:
5
+ test-build:
6
+ docker:
7
+ - image: 'cimg/ruby:2.6.3'
8
+ steps:
9
+ - checkout
10
+ - ruby/install-deps
11
+ - ruby/rspec-test
12
+ workflows:
13
+ eloqua-build:
14
+ jobs:
15
+ - test-build
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /.vscode/
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,28 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ Metrics/AbcSize:
4
+ Enabled: false
5
+
6
+ Metrics/ClassLength:
7
+ Enabled: false
8
+
9
+ Metrics/CyclomaticComplexity:
10
+ Enabled: false
11
+
12
+ Metrics/MethodLength:
13
+ Enabled: false
14
+
15
+ Metrics/ModuleLength:
16
+ Enabled: false
17
+
18
+ Metrics/PerceivedComplexity:
19
+ Enabled: false
20
+
21
+ Metrics/BlockLength:
22
+ Enabled: false
23
+
24
+ Style/Documentation:
25
+ Enabled: false
26
+
27
+ Style/NumericLiterals:
28
+ Enabled: false
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,78 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2021-09-24 18:59:06 UTC using RuboCop version 1.20.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ # Cop supports --auto-correct.
11
+ # Configuration parameters: EnforcedStyle.
12
+ # SupportedStyles: leading, trailing
13
+ Layout/DotPosition:
14
+ Exclude:
15
+ - 'spec/webmocks/eloqua_client_stub.rb'
16
+
17
+ # Offense count: 1
18
+ # Cop supports --auto-correct.
19
+ # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
20
+ # SupportedStyles: space, no_space
21
+ # SupportedStylesForEmptyBraces: space, no_space
22
+ Layout/SpaceInsideBlockBraces:
23
+ Exclude:
24
+ - 'Gemfile'
25
+
26
+ # Offense count: 1
27
+ # Cop supports --auto-correct.
28
+ # Configuration parameters: AllowInHeredoc.
29
+ Layout/TrailingWhitespace:
30
+ Exclude:
31
+ - 'spec/eloqua/api/base_spec.rb'
32
+
33
+ # Offense count: 1
34
+ # Configuration parameters: AllowComments.
35
+ Lint/EmptyFile:
36
+ Exclude:
37
+ - 'lib/eloqua/test.rb'
38
+
39
+ # Offense count: 2
40
+ # Cop supports --auto-correct.
41
+ Lint/RedundantCopDisableDirective:
42
+ Exclude:
43
+ - 'spec/eloqua/api/client_spec.rb'
44
+ - 'spec/eloqua/api/eloqua_external_assets_types_spec.rb'
45
+
46
+ # Offense count: 18
47
+ # Cop supports --auto-correct.
48
+ # Configuration parameters: EnforcedStyle.
49
+ # SupportedStyles: always, always_true, never
50
+ Style/FrozenStringLiteralComment:
51
+ Enabled: false
52
+
53
+ # Offense count: 1
54
+ # Cop supports --auto-correct.
55
+ # Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
56
+ # SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
57
+ Style/HashSyntax:
58
+ Exclude:
59
+ - 'Rakefile'
60
+
61
+ # Offense count: 1
62
+ # Cop supports --auto-correct.
63
+ # Configuration parameters: EnforcedStyle.
64
+ # SupportedStyles: literals, strict
65
+ Style/MutableConstant:
66
+ Exclude:
67
+ - 'lib/eloqua/api/wrapper/version.rb'
68
+
69
+ # Offense count: 7
70
+ # Cop supports --auto-correct.
71
+ # Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
72
+ # SupportedStyles: single_quotes, double_quotes
73
+ Style/StringLiterals:
74
+ Exclude:
75
+ - 'Gemfile'
76
+ - 'Rakefile'
77
+ - 'bin/console'
78
+ - 'lib/eloqua/api/wrapper/version.rb'
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.3
7
+ before_install: gem install bundler -v 1.17.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at 83946734+osama-inayat@users.noreply.github.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in eloqua-api-wrapper.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,78 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ eloqua-api (0.1.0)
5
+ httparty
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.8.0)
11
+ public_suffix (>= 2.0.2, < 5.0)
12
+ ast (2.4.2)
13
+ crack (0.4.5)
14
+ rexml
15
+ diff-lcs (1.4.4)
16
+ hashdiff (1.0.1)
17
+ httparty (0.18.1)
18
+ mime-types (~> 3.0)
19
+ multi_xml (>= 0.5.2)
20
+ mime-types (3.3.1)
21
+ mime-types-data (~> 3.2015)
22
+ mime-types-data (3.2021.0901)
23
+ multi_xml (0.6.0)
24
+ parallel (1.20.1)
25
+ parser (3.0.2.0)
26
+ ast (~> 2.4.1)
27
+ public_suffix (4.0.6)
28
+ rainbow (3.0.0)
29
+ rake (10.5.0)
30
+ regexp_parser (2.1.1)
31
+ rexml (3.2.5)
32
+ rspec (3.10.0)
33
+ rspec-core (~> 3.10.0)
34
+ rspec-expectations (~> 3.10.0)
35
+ rspec-mocks (~> 3.10.0)
36
+ rspec-core (3.10.1)
37
+ rspec-support (~> 3.10.0)
38
+ rspec-expectations (3.10.1)
39
+ diff-lcs (>= 1.2.0, < 2.0)
40
+ rspec-support (~> 3.10.0)
41
+ rspec-mocks (3.10.2)
42
+ diff-lcs (>= 1.2.0, < 2.0)
43
+ rspec-support (~> 3.10.0)
44
+ rspec-support (3.10.2)
45
+ rspec_junit_formatter (0.4.1)
46
+ rspec-core (>= 2, < 4, != 2.12.0)
47
+ rubocop (1.20.0)
48
+ parallel (~> 1.10)
49
+ parser (>= 3.0.0.0)
50
+ rainbow (>= 2.2.2, < 4.0)
51
+ regexp_parser (>= 1.8, < 3.0)
52
+ rexml
53
+ rubocop-ast (>= 1.9.1, < 2.0)
54
+ ruby-progressbar (~> 1.7)
55
+ unicode-display_width (>= 1.4.0, < 3.0)
56
+ rubocop-ast (1.11.0)
57
+ parser (>= 3.0.1.1)
58
+ ruby-progressbar (1.11.0)
59
+ unicode-display_width (2.0.0)
60
+ webmock (3.14.0)
61
+ addressable (>= 2.8.0)
62
+ crack (>= 0.3.2)
63
+ hashdiff (>= 0.4.0, < 2.0.0)
64
+
65
+ PLATFORMS
66
+ ruby
67
+
68
+ DEPENDENCIES
69
+ bundler (~> 1.17)
70
+ eloqua-api!
71
+ rake (~> 10.0)
72
+ rspec (~> 3.0)
73
+ rspec_junit_formatter
74
+ rubocop
75
+ webmock
76
+
77
+ BUNDLED WITH
78
+ 1.17.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Osama Inayat
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,100 @@
1
+ # Eloqua::Api
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/eloqua/api/base`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'eloqua-api-client'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install eloqua-api
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ # To setup the client for ExternalAssetTypes
27
+ client = ::Eloqua::EloquaExternalAssetsTypes.new(
28
+ access_token: 'YOUR-ACCESS-TOKEN', # e.g. djbhyghb27t36hbdhbkjn7y7bhk
29
+ base_url: 'YOUR-BASE-URL') # e.g. 'https://eloqua-api.com/API/REST/{version}'
30
+
31
+ # Getting all ExternalAssetTypes
32
+ client.find_all
33
+ # Finding based on some condition like fetching campaigns having active status or
34
+ # based on name or paginated campaigns you can use optional params
35
+
36
+ find_all method accepts two optional params
37
+ 1- query_params # mostly for pagination
38
+ 2- search_params # for fetching ExternalAssetType objects based on some conditions
39
+
40
+ # Example below fetchs all the ASSET TYPES by paginating them
41
+ client.find_all(query_params: { page: 1, count: 100 })
42
+
43
+ # similarly search_params: {} will search for the specific keys added in the hash
44
+
45
+ # If we want to fetch the Specific ASSET ACTIVITIES simply hit
46
+ client.find(id: 'my asset_type_id')
47
+
48
+ # To setup the client for Campaigns
49
+
50
+ client = ::Eloqua::Campaign.new(
51
+ access_token: 'YOUR-ACCESS-TOKEN', # e.g. djbhyghb27t36hbdhbkjn7y7bhk
52
+ base_url: 'YOUR-BASE-URL') # e.g. 'https://eloqua-api.com/API/REST/{version}'
53
+
54
+ # Same here to get all the campaigns
55
+
56
+ client.find_all
57
+
58
+ # find_all method accepts two optional params
59
+ 1- query_params # mostly for pagination
60
+
61
+ 2- search_params # for fetching campaigns based on some conditions
62
+
63
+ # If Campaigns based on some condtions are needed to be fetched
64
+
65
+ # Lets Say we want to get all active campaigns
66
+
67
+ client.find_all(search_params: { currentStatus: 1 })
68
+ # It will get all the campaigns which are active similarly you can add other
69
+ # query key values based on searchable from eloqua documentation
70
+
71
+ # https://docs.oracle.com/en/cloud/saas/marketing/eloqua-develop/Developers/RESTAPI/Tutorials/search_parameter.htm?cshid=SearchParam
72
+
73
+ # If we want to fetch all those campaigns which are active and name like 'some-name'
74
+ client.find_all(search_params: { currentStatus: 1, name: 'some-name' })
75
+
76
+ # Every time we pass search_params it will do a partials searching
77
+
78
+ # To Fetch Only a Specific Campaign
79
+
80
+ client.find(id: 'campaign_id')
81
+ ```
82
+
83
+
84
+ ## Development
85
+
86
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
87
+
88
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
89
+
90
+ ## Contributing
91
+
92
+ Bug reports and pull requests are welcome on GitHub at https://github.com/osama-inayat/eloqua-api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
93
+
94
+ ## License
95
+
96
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
97
+
98
+ ## Code of Conduct
99
+
100
+ Everyone interacting in the Eloqua::Api::Wrapper project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/osama-inayat/eloqua-api/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "eloqua/api/base"
5
+ require 'eloqua/api/eloqua_external_assets_types'
6
+ require 'eloqua/api/campaign'
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
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,45 @@
1
+ # rubocop:disable all
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "eloqua/api/wrapper/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "eloqua-api-client"
8
+ spec.version = Eloqua::Api::Wrapper::VERSION
9
+ spec.authors = ["Osama Inayat"]
10
+ spec.email = ["83946734+osama-inayat@users.noreply.github.com"]
11
+
12
+ spec.summary = %q{For Communicating with the eloqua api's .}
13
+ # spec.description = %q{TODO: Write a longer description or delete this line.}
14
+ spec.homepage = "https://github.com/osama-inayat/eloqua-api"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
21
+ # spec.metadata["homepage_uri"] = spec.homepage
22
+ # spec.metadata["source_code_uri"] = "https://github.com/osama-inayat/eloqua-api"
23
+ # spec.metadata["changelog_uri"] = "https://github.com/osama-inayat/eloqua-api"
24
+ # else
25
+ # raise "RubyGems 2.0 or newer is required to protect against " \
26
+ # "public gem pushes."
27
+ # end
28
+
29
+ # Specify which files should be added to the gem when it is released.
30
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
31
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
32
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
33
+ end
34
+ spec.bindir = "exe"
35
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
36
+ spec.require_paths = ["lib"]
37
+
38
+ spec.add_development_dependency "bundler", "~> 1.17"
39
+ spec.add_development_dependency "rake", "~> 10.0"
40
+ spec.add_development_dependency "rspec", "~> 3.0"
41
+ spec.add_development_dependency "rubocop"
42
+ spec.add_development_dependency "webmock"
43
+ spec.add_development_dependency "rspec_junit_formatter"
44
+ spec.add_dependency "httparty"
45
+ end
@@ -0,0 +1,10 @@
1
+ DEFAULT_API_VERSION = '2.0'.freeze
2
+ DEFAULT_AUTHORIZATION_TYPE = 'Bearer'.freeze
3
+ TEST_SAMPLE_URL = 'https://eloqua-api-wrapper.com/API/REST/{version}/'.freeze
4
+ TEST_SAMPLE_TOKEN = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9'.freeze
5
+ HTTP_OK_CODE = 200
6
+ HTTP_BAD_REQUEST_CODE = 400
7
+ HTTP_UNAUTHORIZED_CODE = 401
8
+ HTTP_FORBIDDEN_CODE = 403
9
+ HTTP_NOT_FOUND_CODE = 404
10
+ HTTP_SERVER_ERROR = 500
@@ -0,0 +1,38 @@
1
+ ELOQUA_ENDPOINTS = {
2
+ external_assets_types: {
3
+ endpoint: '/assets/external/types',
4
+ method: :get
5
+ }.freeze,
6
+ single_asset_activities: {
7
+ endpoint: '/assets/external/type/{id}',
8
+ method: :get
9
+ }.freeze,
10
+ all_campaigns: {
11
+ endpoint: '/assets/campaigns',
12
+ method: :get
13
+ }.freeze,
14
+ single_campaign: {
15
+ endpoint: '/assets/campaign/{id}',
16
+ method: :get
17
+ }.freeze,
18
+ update_campaign: {
19
+ endpoint: '/assets/campaign/{id}',
20
+ method: :put
21
+ }.freeze,
22
+ create_campaign: {
23
+ endpoint: '/assets/campaign',
24
+ method: :post
25
+ }.freeze,
26
+ activate_campaign: {
27
+ endpoint: '/assets/campaign/active/{id}',
28
+ method: :post
29
+ }.freeze,
30
+ deactive_campaign: {
31
+ endpoint: '/assets/campaign/draft/{id}',
32
+ method: :post
33
+ }.freeze,
34
+ delete_campaign: {
35
+ endpoint: '/assets/campaign/{id}',
36
+ method: :delete
37
+ }.freeze
38
+ }.freeze
@@ -0,0 +1,18 @@
1
+ def mock_request_with(method, url, response, body = {}, request_headers = {})
2
+ WebMock.stub_request(method, url)
3
+ .with(body: body, headers: request_headers)
4
+ .to_return(
5
+ status: 200,
6
+ body: response,
7
+ headers: { content_type: 'application/json' }
8
+ )
9
+ end
10
+
11
+ def mock_request(method, url, response)
12
+ WebMock.stub_request(method, url)
13
+ .to_return(
14
+ status: 200,
15
+ body: response,
16
+ headers: { content_type: 'application/json' }
17
+ )
18
+ end
@@ -0,0 +1,43 @@
1
+ require 'eloqua/api/wrapper/version'
2
+ require 'constants/constants'
3
+ require 'constants/eloqua_endpoints'
4
+ require 'eloqua/api/client'
5
+ require 'helper/url_helper'
6
+
7
+ module Eloqua
8
+ module Api
9
+ class Base
10
+ include UrlHelper
11
+ def initialize(access_token:, base_url:)
12
+ @client = Eloqua::Api::Client.new(access_token: access_token, base_url: base_url)
13
+ end
14
+
15
+ def execute(request_payload)
16
+ @client.call(api_endpoint: request_payload[:endpoint],
17
+ method_type: request_payload[:method],
18
+ params: request_payload[:params])
19
+ end
20
+
21
+ def load_and_execute(api:, id: '', search_params: {}, query_params: {}, payload: {})
22
+ request_payload = ELOQUA_ENDPOINTS[api.to_sym].dup
23
+ unless nil_or_empty?(id.to_s)
24
+ request_payload[:endpoint] =
25
+ sub_id_in_endpoint(request_payload[:endpoint], id.to_s)
26
+ end
27
+ unless nil_or_empty?(search_params) && nil_or_empty?(query_params)
28
+ request_payload[:endpoint] = extend_params_to_url(endpoint: request_payload[:endpoint],
29
+ query_params: query_params,
30
+ search_params: search_params)
31
+ end
32
+ request_payload[:params] = payload.to_json unless nil_or_empty?(payload)
33
+ execute(request_payload)
34
+ end
35
+
36
+ private
37
+
38
+ def nil_or_empty?(value)
39
+ value.nil? || value.empty?
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,36 @@
1
+ require 'eloqua/api/base'
2
+
3
+ module Eloqua
4
+ module Api
5
+ class Campaign < Eloqua::Api::Base
6
+ def find_all(search_params: {}, query_params: {})
7
+ load_and_execute(api: 'all_campaigns', search_params: search_params,
8
+ query_params: query_params)
9
+ end
10
+
11
+ def find(id:)
12
+ load_and_execute(api: 'single_campaign', id: id)
13
+ end
14
+
15
+ def update(id:, payload:)
16
+ load_and_execute(api: 'update_campaign', id: id, payload: payload)
17
+ end
18
+
19
+ def create(payload:)
20
+ load_and_execute(api: 'create_campaign', payload: payload)
21
+ end
22
+
23
+ def activate(id:, query_params:)
24
+ load_and_execute(api: 'activate_campaign', id: id, query_params: query_params)
25
+ end
26
+
27
+ def deactivate(id:)
28
+ load_and_execute(api: 'deactive_campaign', id: id)
29
+ end
30
+
31
+ def destroy(id:)
32
+ load_and_execute(api: 'delete_campaign', id: id)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,60 @@
1
+ require 'httparty'
2
+ require 'helper/url_helper'
3
+ require 'eloqua/api/eloqua_api_exceptions'
4
+ module Eloqua
5
+ module Api
6
+ # provides single source of setting and calling apis
7
+ class Client
8
+ include HTTParty
9
+ include UrlHelper
10
+ include EloquaApiExceptions
11
+
12
+ def initialize(access_token:, base_url:, authorization_type: DEFAULT_AUTHORIZATION_TYPE)
13
+ self.class.base_uri sub_api_version(url: base_url)
14
+ self.class.headers http_headers(access_token, authorization_type)
15
+ end
16
+
17
+ def call(api_endpoint:, method_type: :get, params: {})
18
+ puts api_endpoint
19
+ puts self.class.base_uri
20
+ request_response = self.class.send(method_type, api_endpoint, body: params)
21
+ return request_response.parsed_response if response_successful?(request_response)
22
+
23
+ raise error_class(request_response),
24
+ "Code: #{request_response.code}, response: #{request_response.parsed_response}"
25
+ end
26
+
27
+ private
28
+
29
+ def error_class(response)
30
+ case response.code
31
+ when HTTP_BAD_REQUEST_CODE
32
+ BadRequestError
33
+ when HTTP_UNAUTHORIZED_CODE
34
+ UnAuthorizedError
35
+ when HTTP_FORBIDDEN_CODE
36
+ ForbiddenError
37
+ when HTTP_NOT_FOUND_CODE
38
+ NotFoundError
39
+ when HTTP_SERVER_ERROR
40
+ ServerError
41
+ else
42
+ StandardError
43
+ end
44
+ end
45
+
46
+ def http_headers(access_token, authorization_type)
47
+ {
48
+ 'Content-Type' => 'application/json',
49
+ 'Authorization' => format("#{authorization_type} %s", access_token),
50
+ 'Accept' => 'application/json'
51
+ }
52
+ end
53
+
54
+ def response_successful?(response)
55
+ response.code == 200 || response.code == 201 &&
56
+ (!response.parsed_response.nil? || response.parsed_response != 'Not authenticated.')
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,11 @@
1
+ module EloquaApiExceptions
2
+ class BadRequestError < StandardError; end
3
+
4
+ class UnAuthorizedError < StandardError; end
5
+
6
+ class ForbiddenError < StandardError; end
7
+
8
+ class NotFoundError < StandardError; end
9
+
10
+ class ServerError < StandardError; end
11
+ end
@@ -0,0 +1,15 @@
1
+ require 'eloqua/api/base'
2
+
3
+ module Eloqua
4
+ module Api
5
+ class EloquaExternalAssetsTypes < Eloqua::Api::Base
6
+ def find_all(query_params: {}, search_params: {})
7
+ load_and_execute(api: 'external_assets_types', query_params: query_params, search_params: search_params)
8
+ end
9
+
10
+ def find(id:)
11
+ load_and_execute(api: 'single_asset_activities', id: id)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,7 @@
1
+ module Eloqua
2
+ module Api
3
+ module Wrapper
4
+ VERSION = "0.1.0"
5
+ end
6
+ end
7
+ end
File without changes
@@ -0,0 +1,35 @@
1
+ module UrlHelper
2
+ def sub_api_version(url:)
3
+ url.gsub(/{version}/, DEFAULT_API_VERSION)
4
+ end
5
+
6
+ def sub_id_in_endpoint(endpoint, id)
7
+ endpoint.gsub(/{id}/, id.to_s)
8
+ end
9
+
10
+ def extend_params_to_url(endpoint:, query_params:, search_params:)
11
+ "#{endpoint}?#{query_params_string(query_params)}#{search_params_string(search_params)}"
12
+ end
13
+
14
+ private
15
+
16
+ def query_params_string(query_params)
17
+ return '' if query_params.empty?
18
+
19
+ params_string = ''
20
+ query_params&.each do |key, value|
21
+ params_string += "#{key}=#{value}&"
22
+ end
23
+ params_string
24
+ end
25
+
26
+ def search_params_string(search_params)
27
+ return '' if search_params.empty?
28
+
29
+ search_string = ''
30
+ search_params&.each do |key, value|
31
+ search_string += "#{key}=\'*#{value}*\'"
32
+ end
33
+ search_string.empty? ? search_string : "search=#{search_string}"
34
+ end
35
+ end
metadata ADDED
@@ -0,0 +1,167 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eloqua-api-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Osama Inayat
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-09-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec_junit_formatter
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: httparty
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description:
112
+ email:
113
+ - 83946734+osama-inayat@users.noreply.github.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".circleci/config.yml"
119
+ - ".gitignore"
120
+ - ".rspec"
121
+ - ".rubocop.yml"
122
+ - ".rubocop_todo.yml"
123
+ - ".travis.yml"
124
+ - CODE_OF_CONDUCT.md
125
+ - Gemfile
126
+ - Gemfile.lock
127
+ - LICENSE.txt
128
+ - README.md
129
+ - Rakefile
130
+ - bin/console
131
+ - bin/setup
132
+ - eloqua-api-client.gemspec
133
+ - lib/constants/constants.rb
134
+ - lib/constants/eloqua_endpoints.rb
135
+ - lib/constants/mock_request_helper.rb
136
+ - lib/eloqua/api/base.rb
137
+ - lib/eloqua/api/campaign.rb
138
+ - lib/eloqua/api/client.rb
139
+ - lib/eloqua/api/eloqua_api_exceptions.rb
140
+ - lib/eloqua/api/eloqua_external_assets_types.rb
141
+ - lib/eloqua/api/wrapper/version.rb
142
+ - lib/eloqua/test.rb
143
+ - lib/helper/url_helper.rb
144
+ homepage: https://github.com/osama-inayat/eloqua-api
145
+ licenses:
146
+ - MIT
147
+ metadata: {}
148
+ post_install_message:
149
+ rdoc_options: []
150
+ require_paths:
151
+ - lib
152
+ required_ruby_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ required_rubygems_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ requirements: []
163
+ rubygems_version: 3.0.3
164
+ signing_key:
165
+ specification_version: 4
166
+ summary: For Communicating with the eloqua api's .
167
+ test_files: []