appfuel-service 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
+ SHA1:
3
+ metadata.gz: 6bdddc2bb7ad989546c29e328d3830fb7f619721
4
+ data.tar.gz: fef9d82f6701d0fcfc11b0356de2fc853bfdef99
5
+ SHA512:
6
+ metadata.gz: a3789df3e652aba3038a6d275aaa7487d3a0e1caf94c202ad03c5ae1cbfea48347388f805a3bbf4c12c8d6dc162b296d1b5e6f38e3dab71c64063508126a3b21
7
+ data.tar.gz: 2ef0796fbc8540e5a4f97644930711ce4b639b5b60ca29d504fadafb6b7d77d85ab8ab4aa9159cdef791a4514ec49d9580341688fc6b605db63baae80ce88953
data/.codeclimate.yml ADDED
@@ -0,0 +1,25 @@
1
+ ---
2
+ engines:
3
+ duplication:
4
+ enabled: true
5
+ config:
6
+ languages:
7
+ - ruby
8
+ - javascript
9
+ - python
10
+ - php
11
+ fixme:
12
+ enabled: true
13
+ rubocop:
14
+ enabled: true
15
+ ratings:
16
+ paths:
17
+ - "**.inc"
18
+ - "**.js"
19
+ - "**.jsx"
20
+ - "**.module"
21
+ - "**.php"
22
+ - "**.py"
23
+ - "**.rb"
24
+ exclude_paths:
25
+ - spec/
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
13
+ .ruby-version
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,20 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ - 2.3.3
6
+
7
+ before_install: gem install bundler -v 1.15.0
8
+ deploy:
9
+ provider: rubygems
10
+ api_key:
11
+ secure: IMalY+0x/o7m/T9WC0U+1gxFNIS+GLqMNj+uRJdP5lgftbI/61Tr9nfokIjuTNEbD7TY7DVtUvb8HgYpapmv3B/9ZhPuvmrH1a+UAZpclw9g6Cy4yuV4yEeY1YD3yadPCE0TV4IJNOyRia8sZPtHelBXkkUO7S3nsjrAwSUtFU3Tr7SQtlFIkeNuEKZCpNfYOG3Bw6tTJsabLt1jJ9unm8WDZCDvIwsKezhOjwn1iheZg4ag7w8VNbCtQ+/8zDDo08XjYaf5tXAYvq7TTFll3ukHFFFsUExGazNdHSsNvIXK3GBDnaRXkkSddBRl9Sjagh/ozvhXE+JChlYKpVrm8ZtvI+O3Zpmd5Ho0WZPXWZgj3f+tcPd+KNyJYmedLrX/PUkGCofvpAAkY0REWYpgP5I0lrAW7OMujdygA/z12C3xYwCJYUIlbhP+QFfrwX1M18YfodWbdKuh6DEWO5EHaw+k5HTtCGBwB0WLPPKEZUq/JsGgcEIc3gqLacEoPYsd7aYnge5KF1zu0K2yL/SSoDHv9BkF1w7XItdTaIIEk8JnHSwnDgat+F0XpTzl953GDTTUs4kjIDUCF2nVadQ42NZ6uejLv6ZEqilH/7gVRYWExvf3Tilsr+DzYxiZ1O17sdY4TLj5Tc1rfqNNovIdDplOHrbJTx/GOV1SA6fVqv4=
12
+ gem: 'appfuel-service'
13
+ on:
14
+ tags: true
15
+ repo: rsb/appfuel-service
16
+ addons:
17
+ code_climate:
18
+ repo_token: 89d508f14d4c80f13d4d64635a4639e02c04cad3bb5a165850c32e5be36bf021
19
+ after_success:
20
+ - bundle exec codeclimate-test-reporter
data/CHANGELOG.md ADDED
@@ -0,0 +1,4 @@
1
+ # Change Log
2
+ All notable changes to this project will be documented in this file. (Pending approval) This project adheres to [Semantic Versioning](http://semver.org/). You can read more on this at [keep a change log](http://keepachangelog.com/)
3
+
4
+ # [Unreleased]
@@ -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 rsb.code@gmail.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,11 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in appfuel-service.gemspec
4
+ gemspec
5
+
6
+ #gem 'appfuel', path: '../appfuel'
7
+
8
+ group :test do
9
+ gem "simplecov", "~> 0.14"
10
+ gem "codeclimate-test-reporter", "~> 1.0"
11
+ end
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ [![Build
2
+ Status](https://travis-ci.org/rsb/appfuel-service.svg?branch=master)](https://travis-ci.org/rsb/appfuel-service)
3
+ # Appfuel::Service
4
+
5
+ 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/appfuel/service`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ TODO: Delete this and the text above, and describe your gem
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'appfuel-service'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install appfuel-service
24
+
25
+ ## Usage
26
+
27
+ TODO: Write usage instructions here
28
+
29
+ ## Development
30
+
31
+ 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.
32
+
33
+ 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).
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/appfuel-service. 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.
38
+
39
+ ## Code of Conduct
40
+
41
+ Everyone interacting in the Appfuel::Service project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/appfuel-service/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
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "appfuel/service/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "appfuel-service"
8
+ spec.version = Appfuel::Service::VERSION
9
+ spec.authors = ["Robert Scott-Buccleuch"]
10
+ spec.email = ["rsb.code@gmail.com"]
11
+
12
+ spec.summary = %q{Allow Appfuel to work as a micro service}
13
+ spec.description = %q{Microsevice implementation using Sneakers and RabbitMQ}
14
+ spec.homepage = "https://github.com/rsb/appfuel-service"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "appfuel", "~> 0.2.6"
24
+ spec.add_dependency "sneakers", "~> 2.5"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.15"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec", "~> 3.6"
29
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "appfuel/service"
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(__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,65 @@
1
+ module Appfuel
2
+ module Service
3
+ class MsgRequest < Appfuel::Request
4
+ attr_reader :delivery_info, :properties
5
+
6
+ # metadata properties
7
+ # headers: message headers
8
+ # action_route [String]
9
+ # reply_to: name of rpc response queue
10
+ # correlation_id: id used in rpc to match response
11
+ #
12
+ # @param msg String serialized message from rabbitmq
13
+ # @param delivery_info Hash info used to acknowledge messages
14
+ # @param properties Object properties of the messages
15
+ #
16
+ # @return MsgRequest
17
+ def initialize(msg, delivery_info, properties)
18
+ inputs = validate_inputs(msg)
19
+ action_route = properties.headers['action_route']
20
+ @properties = properties
21
+ @delivery_info = delivery_info
22
+
23
+ super(action_route, inputs)
24
+ end
25
+
26
+ # Rpc requires a reply queue to respond to and a correlation_id to
27
+ # identify that response in the queue. When these two things exist
28
+ # then the request is consided to be an rpc
29
+ #
30
+ # @return [Boolean]
31
+ def rpc?
32
+ !reply_to.nil? && !correlation_id.nil?
33
+ end
34
+
35
+ def reply_to
36
+ properties.reply_to
37
+ end
38
+
39
+ def correlation_id
40
+ properties.correlation_id
41
+ end
42
+
43
+ private
44
+
45
+ def validate_inputs(msg)
46
+ msg = msg.to_s
47
+ return {} if msg.empty?
48
+
49
+ begin
50
+ inputs = JSON.parse(msg)
51
+ fail "message inputs must be a hash" unless data.is_a?(Hash)
52
+
53
+ inputs.deep_symbolize_keys
54
+ rescue => e
55
+ msg = "message request could not parse the inputs: #{e.message}"
56
+ error = RuntimeError.new(msg)
57
+ error.set_backtrace(e.backtrace)
58
+
59
+ raise error
60
+ end
61
+ end
62
+
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,5 @@
1
+ module Appfuel
2
+ module Service
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,57 @@
1
+ module Appfuel
2
+ module Service
3
+ class Worker
4
+ include Sneakers::Worker
5
+ include Appfuel::Application::AppContainer
6
+ include Appfuel::Application::Dispatcher
7
+
8
+ class << self
9
+ def inherited(klass)
10
+ stage_class_for_registration(klass)
11
+ end
12
+ end
13
+
14
+ # Sneakers worker hook to handle messages from RabbitMQ
15
+ #
16
+ #
17
+ # @param msg [String] JSON string of inputs
18
+ # @param delivery_info [Bunny::Delivery::Info]
19
+ # @param properties [Bunny::MessageProperties]
20
+ # @return [Appfuel::Response]
21
+ def work_with_params(msg, delivery_info, properties)
22
+ container = app_container
23
+ request = create_request(msg, delivery_info, properties)
24
+ response = dispatch(request, container)
25
+
26
+ if request.rpc?
27
+ publish_rpc(request, response)
28
+ end
29
+
30
+ ack!
31
+ response
32
+ end
33
+
34
+
35
+ # Publish a response for the rpc request.
36
+ #
37
+ # @param request [MsgRequest]
38
+ # @param respons [Appfuel::Response]
39
+ # @return [Nil]
40
+ def publish_rpc(request, response)
41
+ options = {
42
+ correlation_id: request.correlation_id,
43
+ routing_key: request.reply_to,
44
+ headers: { "action_route" => request.action_route }
45
+ }
46
+ publish(response.to_json, options)
47
+ nil
48
+ end
49
+
50
+ private
51
+
52
+ def create_request(msg, delivery_info, properties)
53
+ Appfuel::Service::MsgRequest.new(msg, delivery_info, properties)
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,5 @@
1
+ require "appfuel"
2
+ require "sneakers"
3
+ require "appfuel/service/version"
4
+ require "appfuel/service/msg_request"
5
+ require "appfuel/service/worker"
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: appfuel-service
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Robert Scott-Buccleuch
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-06-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: appfuel
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.2.6
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.2.6
27
+ - !ruby/object:Gem::Dependency
28
+ name: sneakers
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.5'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.15'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.15'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.6'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.6'
83
+ description: Microsevice implementation using Sneakers and RabbitMQ
84
+ email:
85
+ - rsb.code@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".codeclimate.yml"
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - CHANGELOG.md
95
+ - CODE_OF_CONDUCT.md
96
+ - Gemfile
97
+ - README.md
98
+ - Rakefile
99
+ - appfuel-service.gemspec
100
+ - bin/console
101
+ - bin/setup
102
+ - lib/appfuel/service.rb
103
+ - lib/appfuel/service/msg_request.rb
104
+ - lib/appfuel/service/version.rb
105
+ - lib/appfuel/service/worker.rb
106
+ homepage: https://github.com/rsb/appfuel-service
107
+ licenses: []
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.6.11
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Allow Appfuel to work as a micro service
129
+ test_files: []