evvnt 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6fbf2109eb731d2fff7ed58d0bdfbdb870e9d858943e750d3851cc9f7e8c1fa8
4
+ data.tar.gz: 5ea6252bb8fcbda420fad16d663c617e72f206b986a7ea2c19644ab902dad15a
5
+ SHA512:
6
+ metadata.gz: 291cd38c9c02deca7d0343a90de1025dac83a0314ac94a805ecd6c8758765b61fd4e07cd4e232aa71a4e3a48f704f349692e82358e22f560c1cb6e89d0b27469
7
+ data.tar.gz: 9c909e5592ded00962be89ff4e7ccec6a8d9666c5432ed53d513a9428b329aaf5bb63ff3da4dcff5cf7a0e5b8705bcaabab7488bb15259f78acb2d23d7cfb43d
@@ -0,0 +1,65 @@
1
+ # Ruby CircleCI 2.0 configuration file
2
+ #
3
+ # Check https://circleci.com/docs/2.0/language-ruby/ for more details
4
+ #
5
+ version: 2
6
+ jobs:
7
+ build:
8
+ docker:
9
+ # specify the version you desire here
10
+ - image: circleci/ruby:2.5
11
+
12
+ # Specify service dependencies here if necessary
13
+ # CircleCI maintains a library of pre-built images
14
+ # documented at https://circleci.com/docs/2.0/circleci-images/
15
+ # - image: circleci/postgres:9.4
16
+
17
+ working_directory: ~/evvnt
18
+
19
+ steps:
20
+ - checkout
21
+
22
+ # Download and cache dependencies
23
+ - restore_cache:
24
+ keys:
25
+ - v1-dependencies-{{ checksum "Gemfile.lock" }}
26
+ # fallback to using the latest cache if no exact match is found
27
+ - v1-dependencies-
28
+
29
+ - run:
30
+ name: install dependencies
31
+ command: |
32
+ bundle install --jobs=4 --retry=3 --path vendor/bundle
33
+
34
+ - save_cache:
35
+ paths:
36
+ - ./vendor/bundle
37
+ key: v1-dependencies-{{ checksum "Gemfile.lock" }}
38
+
39
+ - run:
40
+ name: Bunder Audit
41
+ command: gem install bundle-audit && bundle-audit check --update
42
+
43
+ # run tests!
44
+ - run:
45
+ name: Run Rspec
46
+ command: |
47
+ mkdir /tmp/test-results
48
+ TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
49
+
50
+ bundle exec rspec --format progress \
51
+ --format RspecJunitFormatter \
52
+ --out /tmp/test-results/rspec.xml \
53
+ --format progress \
54
+ $TEST_FILES
55
+
56
+ - run:
57
+ name: Code Style Check
58
+ command: rubocop lib --display-style-guide -c ./.rubocop.yml
59
+
60
+ # collect reports
61
+ - store_test_results:
62
+ path: /tmp/test-results
63
+ - store_artifacts:
64
+ path: /tmp/test-results
65
+ destination: test-results
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .env
10
+ .ruby-version
11
+ log
12
+ .byebug_history
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --require spec_helper
2
+ --colour
data/.rubocop.yml ADDED
@@ -0,0 +1,61 @@
1
+ AllCops:
2
+ UseCache: true
3
+ DisplayCopNames: true
4
+ DisplayStyleGuide: true
5
+ TargetRubyVersion: 2.4
6
+ # Include:
7
+ Exclude:
8
+ - 'Gemfile'
9
+ - 'db/**/*'
10
+ - 'config/**/*'
11
+ - 'script/**/*'
12
+ - '**/Rakefile'
13
+ - '**/config.ru'
14
+
15
+ StringLiterals:
16
+ Enabled: false
17
+
18
+ Layout/EmptyLinesAroundClassBody:
19
+ Enabled: false
20
+
21
+ Layout/EmptyLines:
22
+ Enabled: false
23
+
24
+ Layout/EmptyLinesAroundBlockBody:
25
+ Exclude:
26
+ - 'spec/**/*'
27
+
28
+ Style/FrozenStringLiteralComment:
29
+ Enabled: false
30
+
31
+ Style/EmptyMethod:
32
+ Enabled: false
33
+
34
+ Style/MethodMissing:
35
+ Enabled: false
36
+
37
+ # Rails:
38
+ # Enabled: true
39
+
40
+ Metrics/LineLength:
41
+ Max: 90
42
+
43
+ Metrics/MethodLength:
44
+ Max: 20
45
+
46
+ Metrics/AbcSize:
47
+ Enabled: false
48
+
49
+ Lint/AmbiguousBlockAssociation:
50
+ Exclude:
51
+ - 'spec/**/*'
52
+
53
+ Metrics/BlockLength:
54
+ Exclude:
55
+ - 'spec/**/*'
56
+
57
+ Layout/ExtraSpacing:
58
+ Enabled: false
59
+
60
+ Layout/SpaceAroundOperators:
61
+ Enabled: false
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 evvnt.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,97 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ evvnt (0.1.0)
5
+ activesupport (>= 3.0)
6
+ httparty (>= 0.16.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ abstract_class (1.0.1)
12
+ activesupport (5.1.4)
13
+ concurrent-ruby (~> 1.0, >= 1.0.2)
14
+ i18n (~> 0.7)
15
+ minitest (~> 5.1)
16
+ tzinfo (~> 1.1)
17
+ addressable (2.5.2)
18
+ public_suffix (>= 2.0.2, < 4.0)
19
+ ast (2.4.0)
20
+ awesome_print (1.8.0)
21
+ byebug (10.0.0)
22
+ concurrent-ruby (1.0.5)
23
+ crack (0.4.3)
24
+ safe_yaml (~> 1.0.0)
25
+ diff-lcs (1.3)
26
+ dotenv (2.2.1)
27
+ hashdiff (0.3.7)
28
+ httparty (0.16.0)
29
+ multi_xml (>= 0.5.2)
30
+ i18n (0.9.5)
31
+ concurrent-ruby (~> 1.0)
32
+ minitest (5.11.3)
33
+ multi_xml (0.6.0)
34
+ parallel (1.12.1)
35
+ parser (2.5.0.3)
36
+ ast (~> 2.4.0)
37
+ powerpack (0.1.1)
38
+ public_suffix (3.0.2)
39
+ rainbow (3.0.0)
40
+ rake (10.5.0)
41
+ rspec (3.7.0)
42
+ rspec-core (~> 3.7.0)
43
+ rspec-expectations (~> 3.7.0)
44
+ rspec-mocks (~> 3.7.0)
45
+ rspec-collection_matchers (1.1.3)
46
+ rspec-expectations (>= 2.99.0.beta1)
47
+ rspec-core (3.7.1)
48
+ rspec-support (~> 3.7.0)
49
+ rspec-expectations (3.7.0)
50
+ diff-lcs (>= 1.2.0, < 2.0)
51
+ rspec-support (~> 3.7.0)
52
+ rspec-json_matchers (0.1.0)
53
+ abstract_class (~> 1.0, >= 1.0.1)
54
+ awesome_print (~> 1.6)
55
+ rspec (~> 3.0)
56
+ rspec-mocks (3.7.0)
57
+ diff-lcs (>= 1.2.0, < 2.0)
58
+ rspec-support (~> 3.7.0)
59
+ rspec-support (3.7.1)
60
+ rspec_junit_formatter (0.3.0)
61
+ rspec-core (>= 2, < 4, != 2.12.0)
62
+ rubocop (0.53.0)
63
+ parallel (~> 1.10)
64
+ parser (>= 2.5)
65
+ powerpack (~> 0.1)
66
+ rainbow (>= 2.2.2, < 4.0)
67
+ ruby-progressbar (~> 1.7)
68
+ unicode-display_width (~> 1.0, >= 1.0.1)
69
+ ruby-progressbar (1.9.0)
70
+ safe_yaml (1.0.4)
71
+ thread_safe (0.3.6)
72
+ tzinfo (1.2.5)
73
+ thread_safe (~> 0.1)
74
+ unicode-display_width (1.3.0)
75
+ webmock (3.3.0)
76
+ addressable (>= 2.3.6)
77
+ crack (>= 0.3.2)
78
+ hashdiff
79
+
80
+ PLATFORMS
81
+ ruby
82
+
83
+ DEPENDENCIES
84
+ bundler (~> 1.16)
85
+ byebug
86
+ dotenv
87
+ evvnt!
88
+ rake (~> 10.0)
89
+ rspec
90
+ rspec-collection_matchers
91
+ rspec-json_matchers
92
+ rspec_junit_formatter
93
+ rubocop
94
+ webmock
95
+
96
+ BUNDLED WITH
97
+ 1.16.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Bodacious
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,88 @@
1
+ # evvnt
2
+
3
+ [![CircleCI](https://circleci.com/gh/KatanaCode/evvnt.svg?style=svg)](https://circleci.com/gh/KatanaCode/evvnt)
4
+
5
+ Provides a Ruby wrapper around the evvnt APIs
6
+
7
+ ---
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'evvnt'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install evvnt
24
+
25
+ ## Usage
26
+
27
+ Before you begin, you'll need to obtain an API key and secret from evvnt. Once you have that in place, include these in your gem configuration.
28
+
29
+ ### Configuration
30
+
31
+ To configure the gem, create an initializer and define the following block:
32
+
33
+ ``` ruby
34
+ # config/initializers/evvnt.rb
35
+ Evvnt.configure do |config|
36
+ # Print out useful logger info to the Rails log
37
+ config.logger = Rails.logger
38
+ config.debug = Rails.env.development?
39
+ # Your API key and secret
40
+ config.api_key = "..."
41
+ config.api_secret = "secret"
42
+ end
43
+
44
+ ```
45
+
46
+ ### In your code
47
+
48
+ This gem provides an equivalent endpoint for each of the endpoints on the evvnt API. It follows a familiar, idomatic rails pattern to create, fetch, and, update records.
49
+
50
+ For example:
51
+
52
+ ```ruby
53
+ # => Returns all of the categories from the API as an Evvnt::Category object
54
+ @categories = Evvnt::Category.all
55
+
56
+ # The same as the above, aliased
57
+ @categories = Evvnt::Category.index
58
+
59
+ # Returns the first Category
60
+ @category = Evvnt::Category.first
61
+ @category.name # => "Academic / Learning"
62
+
63
+ # Returns the last Category
64
+ @category = Evvnt::Category.last
65
+ @category.name # => "Alternative Investment"
66
+
67
+ # Create a User on the API
68
+ @user = Evvnt::User.create(name: "Sarah Connor", email: "sarah@example.com")
69
+
70
+ # Grab the last User from the API and update their email address:
71
+ @user = Evvnt::User.last
72
+ @user.email = "newemail@example.com"
73
+ @user.save
74
+ ```
75
+
76
+ ## Development
77
+
78
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
79
+
80
+ 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).
81
+
82
+ ## Contributing
83
+
84
+ Bug reports and pull requests are welcome on GitHub at https://github.com/katanacode/evvnt.
85
+
86
+ ## License
87
+
88
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+ require "bundler/setup"
3
+ require "dotenv"
4
+ Dotenv.load
5
+
6
+ require "evvnt"
7
+ Evvnt.configure do |config|
8
+ config.api_key = ENV["API_KEY"]
9
+ config.api_secret = ENV["API_SECRET"]
10
+ config.logger = Logger.new(File.join("log", "development.log"))
11
+ config.debug = true
12
+ end
13
+
14
+ # You can add fixtures and/or initialization code here to make experimenting
15
+ # with your gem easier. You can also use a different console, if you like.
16
+
17
+ # (If you use this, don't forget to add pry to your Gemfile!)
18
+ # require "pry"
19
+ # Pry.start
20
+
21
+ require "irb"
22
+ 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
data/evvnt.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "evvnt/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "evvnt"
7
+ spec.version = Evvnt::VERSION
8
+ spec.authors = ["Bodacious"]
9
+ spec.email = ["bodacious@katanacode.com"]
10
+
11
+ spec.summary = "A wrapper for the EVVNT API"
12
+ spec.description = "Provides a wrapper and helper classes for the EVVNT rest API"
13
+ spec.homepage = "https://github.com/katanacode.com/evvnt"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(spec)/})
18
+ end
19
+ spec.require_paths = ["lib"]
20
+ spec.add_dependency "activesupport", ">= 3.0"
21
+ spec.add_dependency "httparty", ">= 0.16.0"
22
+ spec.add_development_dependency "bundler", "~> 1.16"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec"
25
+ spec.add_development_dependency "rspec_junit_formatter"
26
+ spec.add_development_dependency "rubocop"
27
+ spec.add_development_dependency "webmock"
28
+ spec.add_development_dependency "dotenv"
29
+ spec.add_development_dependency "byebug"
30
+ spec.add_development_dependency "rspec-json_matchers"
31
+ spec.add_development_dependency "rspec-collection_matchers"
32
+ end
@@ -0,0 +1,61 @@
1
+ module Evvnt
2
+ # Internal: Methods for defining API actions for each resource Class.
3
+ #
4
+ module Actions
5
+ private
6
+
7
+ ##
8
+ # A list of the API actions defined on this class
9
+ #
10
+ # Returns Array
11
+ def defined_actions
12
+ @defined_actions ||= []
13
+ end
14
+
15
+ ##
16
+ # Define an action for this class to map on to the Evvnt API for this class's
17
+ # resource.
18
+ #
19
+ # action - A Symbol or String representing the action name. Should be one of the
20
+ # template actions if block is not provided.
21
+ # block - A Proc to be used as the action method definition when custom behaviour
22
+ # is required.
23
+ #
24
+ # Examples
25
+ #
26
+ # class Package < Evvnt::Base
27
+ # # Define using the template `all` method
28
+ # define_action :all
29
+ # define_action :mine do
30
+ # # define the custom behaviour here
31
+ # end
32
+ # end
33
+ #
34
+ # Returns Symbol
35
+ def define_action(action, &block)
36
+ action = action.to_sym
37
+ defined_actions << action unless defined_actions.include?(action)
38
+ if action.in?(Evvnt::ClassTemplateMethods.instance_methods)
39
+ define_class_action(action, &block)
40
+ end
41
+ if action.in?(Evvnt::InstanceTemplateMethods.instance_methods)
42
+ define_instance_action(action, &block)
43
+ end
44
+ action
45
+ end
46
+
47
+ # Define a class-level action on the current class. See {define_action}.
48
+ def define_class_action(action, &block)
49
+ body = block_given? ? block : ClassTemplateMethods.instance_method(action)
50
+ define_singleton_method(action, body)
51
+ singleton_class.send(:alias_method, :all, :index) if action == :index
52
+ singleton_class.send(:alias_method, :find, :show) if action == :show
53
+ end
54
+
55
+ # Define an instance-level action on the current class. See {define_action}.
56
+ def define_instance_action(action, &block)
57
+ body = block_given? ? block : InstanceTemplateMethods.instance_method(action)
58
+ define_method(action, body)
59
+ end
60
+ end
61
+ end
data/lib/evvnt/api.rb ADDED
@@ -0,0 +1,108 @@
1
+ module Evvnt
2
+ # Internal: Handles requests to the EVVNT api and catches their responses.
3
+ module Api
4
+ require "evvnt/api_error"
5
+
6
+ # frozen_string_literal: true
7
+ extend ActiveSupport::Concern
8
+
9
+ ##
10
+ # Allowed HTTP verbs
11
+ HTTP_VERBS = %i[get post put].freeze
12
+
13
+ # Class methods to define on {Evvnt::Base}
14
+ module ClassMethods
15
+ private
16
+
17
+ # Make a request of the EVVNT API.
18
+ #
19
+ # verb - The HTTP verb for the request.
20
+ # path - The path to request from the API.
21
+ # params - A Hash of query params to send with the request.
22
+ # options - A Hash of additional options for the request.
23
+ #
24
+ # Returns HTTParty::Response
25
+ # Raises ArgumentError if the verb is not valid
26
+ def api_request(verb, path, params: {}, options: {})
27
+ unless verb.in?(HTTP_VERBS)
28
+ raise ArgumentError, "Unrecognised HTTP verb '#{verb}'"
29
+ end
30
+ path = sanitize_path(path)
31
+ log_request(verb, path, params)
32
+ response = public_send(verb, path, query: params, headers: headers)
33
+ log_response(response)
34
+ parse_response(response, options)
35
+ end
36
+
37
+ # Log the request being sent to the API
38
+ #
39
+ # verb - A Symbol of the HTTP verb for the request
40
+ # path - A String of the path of the request
41
+ # params - A Hash of the request params being sent to the server
42
+ #
43
+ def log_request(verb, path, params = {})
44
+ return unless Evvnt.configuration.debug
45
+ debug <<~TEXT
46
+ Headers: #{headers}")
47
+ Request: #{verb.to_s.upcase} #{base_uri}#{path} #{params}
48
+ TEXT
49
+ end
50
+
51
+ # Log the response from the API
52
+ #
53
+ # response - The Response object from the API
54
+ #
55
+ def log_response(response)
56
+ return unless Evvnt.configuration.debug
57
+ debug <<~TEXT
58
+ Response: #{response}
59
+ Status: #{response.code}
60
+ TEXT
61
+ end
62
+
63
+ ##
64
+ # Parse a response from the API and create objects from local classes.
65
+ #
66
+ # response - Response object from HTTParty request.
67
+ # options - A Hash of options
68
+ #
69
+ # Returns Array
70
+ # Returns Evvnt::Base subclass
71
+ def parse_response(response, **options)
72
+ json = JSON.parse(response.body)
73
+ json = json[options[:object]] if options.key?(:object)
74
+ json.is_a?(Array) ? json.map { |a| new(a) } : new(json)
75
+ end
76
+
77
+ # Ensure the path is the correct format with a leading slash and ".json" extension
78
+ #
79
+ # path - A String with the API request path.
80
+ #
81
+ # Returns String
82
+ def sanitize_path(path)
83
+ path = "/" + path unless path.starts_with?('/')
84
+ path += ".json" unless path.ends_with?(".json")
85
+ path
86
+ end
87
+
88
+ ##
89
+ # Headers to be sent with every request.
90
+ #
91
+ # Returns Hash
92
+ def headers
93
+ {
94
+ "Authorization" => "Basic #{auth}",
95
+ "Content-Type" => "application/json",
96
+ "Accept" => "application/json"
97
+ }
98
+ end
99
+
100
+ ##
101
+ # Key and secret as Base64 string.
102
+ def auth
103
+ Base64.encode64([Evvnt.configuration.api_key,
104
+ Evvnt.configuration.api_secret].join(":"))
105
+ end
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,4 @@
1
+ module Evvnt
2
+ class ApiError < StandardError
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Evvnt
2
+ class AudienceReach < Evvnt::Base
3
+ end
4
+ end