icalia-foresight 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.3
5
+ before_install: gem install bundler -v 1.13.6
@@ -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 TODO: Write your email address. 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,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in icalia-foresight.gemspec
4
+ gemspec
5
+
6
+ gem 'byebug'
7
+ gem 'pry'
8
+
9
+ gem 'gem-release', '~> 0.7.4'
10
+
11
+ # Run specs automatically:
12
+ gem 'guard-rspec', '~> 4.7', '>= 4.7.3', require: false
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 TODO: Write your name
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.
@@ -0,0 +1,48 @@
1
+ # Icalia Foresight Ruby Client & SDK
2
+
3
+ [![Code Climate](https://codeclimate.com/repos/5863f2121beb7226ee000d90/badges/b84e88f6531d5b37f105/gpa.svg)](https://codeclimate.com/repos/5863f2121beb7226ee000d90/feed) [![Issue Count](https://codeclimate.com/repos/5863f2121beb7226ee000d90/badges/b84e88f6531d5b37f105/issue_count.svg)](https://codeclimate.com/repos/5863f2121beb7226ee000d90/feed) [![Codeship Status](https://codeship.com/projects/eb4ffe10-af55-0134-446f-46de212d7bfb/status?branch=master)](https://codeship.com/projects/eb4ffe10-af55-0134-446f-46de212d7bfb) [![Test Coverage](https://codeclimate.com/repos/5863f2121beb7226ee000d90/badges/b84e88f6531d5b37f105/coverage.svg)](https://codeclimate.com/repos/5863f2121beb7226ee000d90/coverage)
4
+
5
+ This gem is used to communicate with all of the services that conform Icalia Foresight
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'icalia-foresight'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install icalia-foresight
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run
30
+ the tests. You can also run `bin/console` for an interactive prompt that will allow you to
31
+ experiment.
32
+
33
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new
34
+ version, update the version number in `version.rb`, and then run `bundle exec rake release`, which
35
+ will create a git tag for the version, push git commits and tags, and push the `.gem` file to
36
+ [rubygems.org](https://rubygems.org).
37
+
38
+ ## Contributing
39
+
40
+ Bug reports and pull requests are welcome on GitHub at https://github.com/IcaliaLabs/foresight-gem.
41
+ This project is intended to be a safe, welcoming space for collaboration, and contributors are
42
+ expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
43
+
44
+
45
+ ## License
46
+
47
+ The gem is available as open source under the terms of the
48
+ [MIT License](http://opensource.org/licenses/MIT).
@@ -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
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "icalia/foresight"
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
+ require "byebug"
12
+ Pry.start
13
+
14
+ # require "irb"
15
+ # IRB.start
@@ -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,11 @@
1
+ # 1: Use ruby 2.3.3 as base:
2
+ FROM ruby:2.3.3
3
+
4
+ # 2: We'll set this gem path as the working directory
5
+ WORKDIR /usr/src/lib
6
+
7
+ # 3: We'll set the working dir as HOME and add the app's binaries path to $PATH:
8
+ ENV HOME=/usr/src/lib PATH=/usr/src/lib/bin:$PATH
9
+
10
+ # 4: Set the default command:
11
+ CMD ["guard"]
@@ -0,0 +1,37 @@
1
+ version: '2.1'
2
+
3
+ volumes:
4
+ foresight-gems:
5
+ driver: local
6
+
7
+ services:
8
+
9
+ lib:
10
+ build:
11
+ context: .
12
+ dockerfile: dev.Dockerfile
13
+ image: icalialabs/foresight-gem:development
14
+
15
+ volumes:
16
+ # Mount our app code directory (".") into our app containers at the `/usr/src/lib` folder:
17
+ - .:/usr/src/lib
18
+ # Mount the 'archon-gems' volume on the folder that stores bundled gems:
19
+ - foresight-gems:/usr/local/bundle
20
+
21
+ # Keep the stdin open, so we can attach to our app container's process
22
+ # and do things such as byebug, etc:
23
+ stdin_open: true
24
+
25
+ # Enable sending signals (CTRL+C, CTRL+P + CTRL+Q) into the container:
26
+ tty: true
27
+
28
+ # The command:
29
+ command: guard
30
+
31
+ extra_hosts:
32
+ - "artanis-dev.icalialabs.com:13.85.80.155"
33
+
34
+ environment:
35
+ ARTANIS_URL: ${ARTANIS_URL:-http://artanis.icalialabs.com}
36
+ ARTANIS_CLIENT_KEY: ${ARTANIS_CLIENT_KEY:-SOME_KEY}
37
+ ARTANIS_CLIENT_SECRET: ${ARTANIS_CLIENT_SECRET:-SOME_SECRET}
@@ -0,0 +1,3 @@
1
+ ARTANIS_URL=http://artanis-dev.icalialabs.com
2
+ ARTANIS_CLIENT_KEY=SOME_KEY
3
+ ARTANIS_CLIENT_SECRET=SOME_SECRET
@@ -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 'icalia/foresight/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "icalia-foresight"
8
+ spec.version = Icalia::Foresight::VERSION
9
+ spec.authors = ["Roberto Quintanilla"]
10
+ spec.email = ["vov@icalialabs.com"]
11
+
12
+ spec.summary = %q{Icalia Foresight SDK/Client library for Ruby}
13
+ spec.description = %q{Icalia Foresight SDK/Client library for Ruby}
14
+ spec.homepage = "http://github.com/IcaliaLabs/foresight-gem"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ all_things_rails_version_string = ['~> 4.2']
25
+ spec.add_runtime_dependency %q<activemodel>, all_things_rails_version_string
26
+
27
+ spec.add_runtime_dependency "faraday", "~> 0.10.0"
28
+ spec.add_runtime_dependency "json_api_client", "~> 1.3"
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.13"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "rspec", "~> 3.0"
33
+ end
@@ -0,0 +1,14 @@
1
+ require 'active_support'
2
+
3
+ module Icalia
4
+ module Artanis
5
+ extend ActiveSupport::Autoload
6
+
7
+ autoload :ClientAuth
8
+ autoload :HttpConnection
9
+ autoload :Resource
10
+ autoload :ResourceQueryBuilder
11
+ autoload :AccessToken
12
+ autoload :User
13
+ end
14
+ end
@@ -0,0 +1,17 @@
1
+ module Icalia
2
+ module Artanis
3
+ class AccessToken < Resource
4
+ def self.find(*args)
5
+ a = super
6
+ a.first if a.any?
7
+ end
8
+
9
+ def self.find_by(attributes = {})
10
+ raise "No attributes" unless attributes.any?
11
+ a = where(attributes).limit(1).to_a
12
+ return nil unless a.any?
13
+ a.first
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,63 @@
1
+ require 'faraday'
2
+ require 'active_model'
3
+ require 'active_support/core_ext/hash/indifferent_access'
4
+ require 'active_support/core_ext/numeric/conversions'
5
+
6
+ module Icalia
7
+ module Artanis
8
+ class ClientAuth
9
+ include ActiveModel::Model
10
+ attr_accessor :access_token, :token_type, :created_at
11
+
12
+ def created_at=(value)
13
+ value = Time.at(value) if value.is_a? Integer
14
+ @created_at = value
15
+ end
16
+
17
+ def ==(other)
18
+ other.is_a?(self.class) && other.access_token == access_token
19
+ end
20
+
21
+ def to_s
22
+ access_token
23
+ end
24
+
25
+ def to_authorization_header
26
+ "Bearer #{to_s}"
27
+ end
28
+
29
+ #Override Icalia::Artanis::ClientAuth.store to define a custom Cache. By default it uses MemoryStore.
30
+ cattr_accessor :store do
31
+ ActiveSupport::Cache::MemoryStore.new
32
+ end
33
+
34
+ cattr_reader :http do
35
+ artanis_url = ENV.fetch 'ARTANIS_URL', 'https://artanis.icalialabs.com'
36
+
37
+ Faraday.new(url: artanis_url) do |faraday|
38
+ faraday.request :url_encoded # form-encode POST params
39
+ faraday.response :logger # log requests to STDOUT
40
+ faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
41
+ end
42
+ end
43
+
44
+ cattr_reader :client_credentials_authorization_header do
45
+ client_key = ENV.fetch 'ARTANIS_CLIENT_KEY'
46
+ client_secret = ENV.fetch 'ARTANIS_CLIENT_SECRET'
47
+ "Basic #{::Base64.strict_encode64("#{client_key}:#{client_secret}")}"
48
+ end
49
+
50
+ def self.fetch
51
+ store.fetch 'my-artanis-client-token' do
52
+ response = http.post do |req|
53
+ req.url '/oauth/token'
54
+ req.headers['Authorization'] = client_credentials_authorization_header
55
+ req.params['grant_type'] = 'client_credentials'
56
+ end
57
+ # Return a new instance of the Client Auth:
58
+ new ActiveSupport::JSON.decode(response.body)
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,10 @@
1
+ module Icalia
2
+ module Artanis
3
+ class HttpConnection < JsonApiClient::Connection
4
+ def run(request_method, path, params = {}, headers = {})
5
+ headers.reverse_merge! 'Authorization' => ClientAuth.fetch.to_authorization_header
6
+ super
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,15 @@
1
+ require 'json_api_client'
2
+
3
+ module Icalia
4
+ module Artanis
5
+ class Resource < JsonApiClient::Resource
6
+ # set the api base url in an abstract base class
7
+ self.site = ENV.fetch 'ARTANIS_URL', 'https://artanis.icalialabs.com'
8
+
9
+ self.connection_class = HttpConnection
10
+ self.query_builder = ResourceQueryBuilder
11
+ self.json_key_format = :dasherized_key
12
+ self.route_format = :dasherized_route
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,17 @@
1
+ require 'json_api_client'
2
+
3
+ module Icalia
4
+ module Artanis
5
+ class ResourceQueryBuilder < JsonApiClient::Query::Builder
6
+ def limit(value)
7
+ @pagination_params[:limit] = value
8
+ self
9
+ end
10
+
11
+ def offset(value)
12
+ @pagination_params[:offset] = value
13
+ self
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,6 @@
1
+ module Icalia
2
+ module Artanis
3
+ class User
4
+ end
5
+ end
6
+ end