ereignishorizont-client 2.0.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: d4d35076e57d1e659220bf2f0a67b46eb7b33196
4
+ data.tar.gz: 097716efefcd1baa5b29aa96897cad0f1f85252a
5
+ SHA512:
6
+ metadata.gz: 4b9980bebcdeec1eb2f0b5a539fc9ba372ab2cb706ab7fe12e602ac686df5b4571789fc61a7cdc2a7ab9ff3479f764a1b5b8cfaabab9cf6d4ab2a9c57dee4e46
7
+ data.tar.gz: 2963fbd34d9ed7bc9ba450aa23e90843f9bd6fdafe1346f2a94474fb48e87266f93b6c031a12b95e21833ab225d66efa85c24deb0c5dc365e5bc2b01e251f52a
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ event_girl_client
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.0
data/.travis.yml ADDED
@@ -0,0 +1,13 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.0
4
+ - 2.2.2
5
+ - 2.3.0
6
+ script: bundle exec rspec spec
7
+ notifications:
8
+ email:
9
+ - tam.eastley@gmail.com
10
+ - susanne.dewein@gmail.com
11
+ - felix@mohnert.de
12
+ webhooks:
13
+ secure: YgIzmRfVkBhyjLeEhtnGuZ4s0J3jw1jBxrP0qh6VLx+I2bGszuv1VJAAKhhUmqXi5qyAaOeNRKYmwE1UN8P6UupmtNpxBPpki+tzZ07rHkNqC9EkCg2NgzhcNV654XjXQNEyUb4I54bpbMbQXa+aX3RokfuxWR4ernb61TelwjU=
data/CHANGELOG.md ADDED
@@ -0,0 +1,17 @@
1
+ # Changelog
2
+
3
+ ## v1.2.0
4
+ - Fix openssl requirement
5
+
6
+ ## v1.2.0
7
+ - Add support for optional content parameter
8
+ - EventGirl::Client.send_event is deprecated, use #send! instead
9
+ - Allows setting the url to protocol + hostname only, w/o path
10
+
11
+ ## v1.1.1
12
+ - Adds SSL-support
13
+
14
+ ## v1.1.0
15
+ - Fix Ruby 1.9.3 issues
16
+ - Removed ActiveSupport dependency
17
+ - Add ``--debug`` option for cmd line tool
@@ -0,0 +1,22 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality.
6
+
7
+ Examples of unacceptable behavior by participants include:
8
+
9
+ * The use of sexualized language or imagery
10
+ * Personal attacks
11
+ * Trolling or insulting/derogatory comments
12
+ * Public or private harassment
13
+ * Publishing other's private information, such as physical or electronic addresses, without explicit permission
14
+ * Other unethical or unprofessional conduct.
15
+
16
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team.
17
+
18
+ This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community.
19
+
20
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
21
+
22
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.2.0, available at [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in event_girl_client.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Absolventa GmbH, Susanne Dewein, Tam Eastley
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # Ereignishorizont Client [![Code Climate](https://codeclimate.com/github/Absolventa/ereignishorizont-client.png)](https://codeclimate.com/github/Absolventa/ereignishorizont-client) [![Build Status](https://travis-ci.org/Absolventa/ereignishorizont-client.png?branch=master)](https://travis-ci.org/Absolventa/ereignishorizont-client) [![Gem Version](https://badge.fury.io/rb/ereignishorizont.png)](http://badge.fury.io/rb/ereignishorizont)
2
+
3
+ Ereignishorizont Client can be used in your own app to send
4
+ events to an external Ereignishorizont Application such as
5
+ [ereignishorizont.herokuapp.com](https://ereignishorizont.herokuapp.com).
6
+ It is the gem for [Ereignishorizont](https://github.com/Absolventa/ereignishorizont)
7
+ (formerly known as 'Event Girl') which was part of a project
8
+ for the [Rails Girls Summer of Code](http://railsgirlssummerofcode.org).
9
+ Its three main contributors are the
10
+ Rails Girls Susanne and Tam, and their coach Carsten, who worked on the project
11
+ from July 2 - September 30, 2013 at the [ABSOLVENTA](https://www.absolventa.de)
12
+ offices in Berlin.
13
+
14
+ Using an initializer file for Rails, you can do:
15
+
16
+ Ereignishorizont::Client.configure do |config|
17
+ config.api_token = 'my-api-token'
18
+ config.url = 'http://my-ereignishorizont-endpoint.example.com'
19
+ end
20
+
21
+ The gem also includes a command line executable. See ``ereignishorizont -h`` for further details.
22
+
23
+ ## Installation
24
+
25
+ Add this line to your application's Gemfile:
26
+
27
+ gem 'ereignishorizont-client'
28
+
29
+ And then execute:
30
+
31
+ $ bundle
32
+
33
+ Or install it yourself as:
34
+
35
+ $ gem install ereignishorizont-client
36
+
37
+ ## Usage
38
+
39
+ Get the URL you want to send the event to (example: https://ereignishorizont.herokuapp.com/incoming_events)
40
+
41
+ Create a remote side and get its API token via the Ereignishorizont application.
42
+
43
+ Create an instance and start sending events:
44
+
45
+ client = Ereignishorizont::Client.new('http://example.com', 'mytoken')
46
+ client.send! 'hello from ereignishorizont-client'
47
+
48
+ You can optionally send additional payload data:
49
+
50
+ client = Ereignishorizont::Client.new('http://example.com', 'mytoken')
51
+ client.send! 'hello from ereignishorizont-client', 'Optional additional data that will not be matched'
52
+
53
+ ## Contributing
54
+
55
+ 1. Fork it
56
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
57
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
58
+ 4. Push to the branch (`git push origin my-new-feature`)
59
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ # vim: ft=ruby
4
+
5
+ begin
6
+ require 'ereignishorizont/client'
7
+ rescue LoadError
8
+ require 'rubygems'
9
+ require 'ereignishorizont/client'
10
+ end
11
+
12
+ require 'optparse'
13
+
14
+ Version = Ereignishorizont::Client::VERSION.dup
15
+
16
+ options = {}
17
+ option_parser = OptionParser.new do |opts|
18
+ opts.banner = "Usage: event_girl [options] EVENTNAME OPTIONAL_DATA"
19
+
20
+ opts.separator ""
21
+ opts.separator "Options:"
22
+
23
+ opts.on('-t', '--token TOKEN', 'Authentication token') do |token|
24
+ options[:api_token] = token
25
+ end
26
+ opts.on('-s', '--site URL', 'URL of API endpoint') do |url|
27
+ options[:url] = url
28
+ end
29
+ opts.on('--debug', 'Display full stack traces') do
30
+ options[:debug] = true
31
+ end
32
+ opts.on_tail('--version', 'Display version and exit') do
33
+ puts opts.ver
34
+ puts
35
+ puts "A Ruby client library to connect to the ereignishorizont app,"
36
+ puts "written by Susanne Dewein, Tam Eastley, Carsten Zimmermann"
37
+ puts "as part of the ABSOLVENTA Rails Girls Summer of Code 2013."
38
+ puts
39
+ puts "© 2013-2016 Absolventa GmbH"
40
+ puts "This is free software; see the source for copying conditions."
41
+ puts "There is NO warranty; not even for MERCHANTABILITY or FITNESS"
42
+ puts "FOR A PARTICULAR PURPOSE. Licensed under the MIT license."
43
+ exit
44
+ end
45
+ opts.on('-h', '--help', 'Display this help screen') do
46
+ puts opts
47
+ exit
48
+ end
49
+ end
50
+
51
+ option_parser.parse!
52
+
53
+ if ARGV.empty?
54
+ puts "E: Need to specify an event name to send"
55
+ exit 1
56
+ end
57
+
58
+ begin
59
+ client = Ereignishorizont::Client.new(options[:url], options[:api_token])
60
+ client.send!(ARGV[0], ARGV[1])
61
+ rescue => e
62
+ puts "E: #{e.message}"
63
+ puts e.backtrace if options[:debug]
64
+ exit 1
65
+ end
66
+ exit 0
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ereignishorizont/client'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ereignishorizont-client"
8
+ spec.version = Ereignishorizont::Client::VERSION
9
+ spec.authors = ["Susanne Dewein", "Tam Eastley", "Carsten Zimmermann"]
10
+ spec.email = ["susanne.dewein@gmail.com", "tam.eastley@gmail.com", "cz@aegisnet.de"]
11
+ spec.description = %q{Ruby client library to connect to ereignishorizont app}
12
+ spec.summary = %q{Ruby client library to connect to ereignishorizont app}
13
+ spec.homepage = "https://github.com/Absolventa/ereignishorizont-client"
14
+ spec.license = "MIT"
15
+
16
+ spec.required_ruby_version = '>= 2.1'
17
+
18
+ spec.files = `git ls-files`.split($/)
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", ">= 1.3"
24
+ spec.add_development_dependency "rspec", "~> 2.14"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "webmock"
27
+ end
@@ -0,0 +1,77 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+ require 'openssl'
4
+
5
+ require 'rubygems'
6
+
7
+ module Ereignishorizont
8
+ class Client
9
+
10
+ VERSION = '2.0.0'
11
+
12
+ # Class-wide configuration
13
+ @@api_token = nil
14
+ @@url = nil
15
+
16
+ attr_reader :api_token, :url
17
+
18
+ def initialize(url = nil, api_token = nil)
19
+ @url = (url || self.class.url)
20
+ @api_token = (api_token || self.class.api_token).to_s
21
+ raise ArgumentError.new('No url provided.') unless @url
22
+ end
23
+
24
+ # @deprecated Use {#send!} instead.
25
+ def send_event(*args)
26
+ send!(*args)
27
+ end
28
+
29
+ # POSTs a string to the event_girl server.
30
+ def send!(title, content = nil)
31
+ uri = URI.parse(url)
32
+
33
+ # Auto-correct missing trailing slash
34
+ path = uri.path == '' ? '/' : uri.path
35
+
36
+ # This is all the post request stuff.
37
+ req = Net::HTTP::Post.new(path)
38
+
39
+ # The request format and content type is json
40
+ req['Accept'] = "application/json"
41
+ req['Content-Type'] = "application/json"
42
+
43
+ # This takes the entered api token and title. This is what is sent. It is a HASH!
44
+ req.body = '{"api_token":"' + api_token + '","incoming_event":{"title":"' + title.to_s + '","content":"' + content.to_s + '"}}'
45
+
46
+ # The request is sent via HTTP to the host and port. You also get a response
47
+ # ex: 201 (it worked)
48
+ http = Net::HTTP.new(uri.host, uri.port)
49
+
50
+ http.use_ssl = ssl?
51
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
52
+
53
+ http.request(req)
54
+ end
55
+
56
+ def self.configure
57
+ yield self if block_given?
58
+ end
59
+
60
+ # class attribute accessors:
61
+ class_variables.map{|cvar| cvar.to_s.gsub('@@', '') }.each do |cattr|
62
+ define_singleton_method cattr do
63
+ class_variable_get :"@@#{cattr}"
64
+ end
65
+ define_singleton_method "#{cattr}=" do |value|
66
+ class_variable_set "@@#{cattr}", value
67
+ end
68
+ end
69
+
70
+ private
71
+
72
+ def ssl?
73
+ !!/^https:/.match(url)
74
+ end
75
+
76
+ end
77
+ end
@@ -0,0 +1,98 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ereignishorizont::Client do
4
+
5
+ subject { described_class.new('http://example.com/incoming_events', 'foobar') }
6
+
7
+ context 'with class-level configuration' do
8
+ %w(api_token url).each do |accessor|
9
+ it { expect(described_class).to respond_to accessor }
10
+ it { expect(described_class).to respond_to "#{accessor}=" }
11
+ end
12
+
13
+ describe '.configure' do
14
+ it 'sets configuration via a block' do
15
+ described_class.configure do |config|
16
+ config.api_token = 'abcdef'
17
+ config.url = 'https://eg.example.com'
18
+ end
19
+ expect(described_class.api_token).to eql 'abcdef'
20
+ expect(described_class.url).to eql 'https://eg.example.com'
21
+ end
22
+ end
23
+ end
24
+
25
+ it 'creates instances with two arguments' do
26
+ expect(described_class.instance_method(:initialize).arity).to eql(-1)
27
+ end
28
+
29
+ it 'raises an error when url is omitted' do
30
+ expect do
31
+ described_class.new(nil, 'abc')
32
+ end.to raise_error ArgumentError
33
+ end
34
+
35
+ it 'sets the api_token' do
36
+ subject = described_class.new('', 'abcxyz')
37
+ expect(subject.api_token).to eql 'abcxyz'
38
+ end
39
+
40
+ it 'sets the url' do
41
+ subject = described_class.new('http://localhost:3000', nil)
42
+ expect(subject.url).to eql 'http://localhost:3000'
43
+ end
44
+
45
+ describe '#send_event' do
46
+ it 'still responds to send_event' do
47
+ expect(subject).to respond_to :send_event
48
+ end
49
+
50
+ it 'delegates to #send!' do
51
+ subject.should_receive(:send!).with('foo', 'bar')
52
+ subject.send_event('foo', 'bar')
53
+ end
54
+ end
55
+
56
+ describe '#send!' do
57
+ it 'requires the event title and supports content optionally' do
58
+ expect(subject.method(:send!).arity).to eql(-2)
59
+ end
60
+
61
+ it 'adds a missing trailing slash' do
62
+ url = 'http://eg.example.com'
63
+ stub_request(:post, "#{url}/")
64
+ subject = described_class.new url
65
+ expect do
66
+ subject.send! ''
67
+ end.not_to raise_error
68
+ end
69
+
70
+ it 'sends json data' do
71
+ title = 'event girl test'
72
+ json = '{"api_token":"' + subject.api_token + '","incoming_event":{"title":"' + title + '","content":""}}'
73
+ stub_request(:post, subject.url).
74
+ with(body: json)
75
+ subject.send! title
76
+ end
77
+
78
+ it 'allows sending of optional content' do
79
+ title = 'event girl test'
80
+ content = 'this is additional payload data'
81
+ json = '{"api_token":"' + subject.api_token + '","incoming_event":{"title":"' + title + '","content":"' + content + '"}}'
82
+ stub_request(:post, subject.url).
83
+ with(body: json)
84
+ subject.send! title, content
85
+ end
86
+
87
+ it 'sends json headers' do
88
+ stub_request(:post, subject.url).
89
+ with(
90
+ headers: {
91
+ 'Accept' => 'application/json',
92
+ 'Content-Type' => 'application/json'
93
+ }
94
+ )
95
+ subject.send! 'event girl test'
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ Bundler.setup
4
+
5
+ require 'ereignishorizont/client'
6
+ require 'webmock/rspec'
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ereignishorizont-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Susanne Dewein
8
+ - Tam Eastley
9
+ - Carsten Zimmermann
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2016-05-30 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: bundler
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: '1.3'
29
+ - !ruby/object:Gem::Dependency
30
+ name: rspec
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: '2.14'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '2.14'
43
+ - !ruby/object:Gem::Dependency
44
+ name: rake
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ - !ruby/object:Gem::Dependency
58
+ name: webmock
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ description: Ruby client library to connect to ereignishorizont app
72
+ email:
73
+ - susanne.dewein@gmail.com
74
+ - tam.eastley@gmail.com
75
+ - cz@aegisnet.de
76
+ executables:
77
+ - ereignishorizont
78
+ extensions: []
79
+ extra_rdoc_files: []
80
+ files:
81
+ - ".gitignore"
82
+ - ".ruby-gemset"
83
+ - ".ruby-version"
84
+ - ".travis.yml"
85
+ - CHANGELOG.md
86
+ - CODE_OF_CONDUCT.md
87
+ - Gemfile
88
+ - LICENSE.txt
89
+ - README.md
90
+ - Rakefile
91
+ - bin/ereignishorizont
92
+ - ereignishorizont-client.gemspec
93
+ - lib/ereignishorizont/client.rb
94
+ - spec/client_spec.rb
95
+ - spec/spec_helper.rb
96
+ homepage: https://github.com/Absolventa/ereignishorizont-client
97
+ licenses:
98
+ - MIT
99
+ metadata: {}
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '2.1'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 2.5.1
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: Ruby client library to connect to ereignishorizont app
120
+ test_files:
121
+ - spec/client_spec.rb
122
+ - spec/spec_helper.rb