event_girl_client 1.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: c2397f94943016aa59c3c0fca30206895f661e49
4
+ data.tar.gz: 0b5c3e16b4ef47c32ab7cd1bcd801bae5e36d114
5
+ SHA512:
6
+ metadata.gz: 98c230c7d5b13868f75c3b312f0931668c758730106004cd4ebe910818db11bcc52653df5607fbb36d88901b61a901bad0e1aa96a2a7431cf19ef7fcc5d00f81
7
+ data.tar.gz: aefc97b7038b3cc8bd43f7a9b5df2a7cfc02d2ac58586215aececfe4602c817fa16639bf7f485b2504ca0a5577bb3ddb189cab38778a9de3daccdf4a2be87f7f
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.0.0-p247
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,50 @@
1
+ # EventGirlClient
2
+
3
+ EventGirlClient can be used in your own app to send
4
+ events to an external Event Girl Application such as
5
+ [event-girl.herokuapp.com](event-girl.herokuapp.com).
6
+ It is the gem for [Event Girl](https://github.com/Absolventa/event_girl)
7
+ which was part of a project
8
+ for the [Rails Girls Summer of Code](http://railsgirlssummerofcode.org).
9
+ Its two main contributors are the
10
+ Rails Girls Susanne and Tam who worked on the project
11
+ from July 2 - September 30, 2013 at the [ABSOLVENTA](http://www.absolventa.de)
12
+ offices in Berlin.
13
+
14
+ Using an initializer file for Rails, you can do:
15
+
16
+ EventGirl::Client.configure do |config|
17
+ config.api_token = 'my-api-token'
18
+ config.url = 'http://my-eventgirl-endpoint.example.com'
19
+ end
20
+
21
+ ## Installation
22
+
23
+ Add this line to your application's Gemfile:
24
+
25
+ gem 'event_girl_client'
26
+
27
+ And then execute:
28
+
29
+ $ bundle
30
+
31
+ Or install it yourself as:
32
+
33
+ $ gem install event_girl_client
34
+
35
+ ## Usage
36
+
37
+ - Get the URL you want to send the event to
38
+ - example: www.event-girl.herokuapp.com/incoming_events
39
+ - Create an API token via the Event Girl application
40
+ - Insert the `send_event(title)` method into your code
41
+ - title must be the title of the event you want to track
42
+ - Start sending events!
43
+
44
+ ## Contributing
45
+
46
+ 1. Fork it
47
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
48
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
49
+ 4. Push to the branch (`git push origin my-new-feature`)
50
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/event_girl ADDED
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env ruby
2
+ # vim: ft=ruby
3
+ # encoding: utf-8
4
+
5
+ begin
6
+ require 'event_girl_client'
7
+ rescue LoadError
8
+ require 'rubygems'
9
+ require 'event_girl_client'
10
+ end
11
+
12
+ require 'optparse'
13
+
14
+ Version = EventGirl::Client::VERSION.dup
15
+
16
+ options = {}
17
+ option_parser = OptionParser.new do |opts|
18
+ opts.banner = "Usage: event_girl [options] EVENTNAME"
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_tail('--version', 'Display version and exit') do
30
+ puts opts.ver
31
+ puts
32
+ puts "A Ruby client library to connect to the event_girl app,"
33
+ puts "written by Susanne Dewein, Tam Eastley, Carsten Zimmermann"
34
+ puts "as part of the ABSOLVENTA Rails Girls Summer of Code 2013."
35
+ puts
36
+ puts "© 2013 Absolventa GmbH"
37
+ puts "This is free software; see the source for copying conditions."
38
+ puts "There is NO warranty; not even for MERCHANTABILITY or FITNESS"
39
+ puts "FOR A PARTICULAR PURPOSE. Licensed under the MIT license."
40
+ exit
41
+ end
42
+ opts.on('-h', '--help', 'Display this help screen') do
43
+ puts opts
44
+ exit
45
+ end
46
+ end
47
+
48
+ option_parser.parse!
49
+
50
+ if ARGV.empty?
51
+ puts "E: Need to specify an event name to send"
52
+ exit 1
53
+ end
54
+
55
+ client = EventGirl::Client.new(options[:url], options[:api_token])
56
+ client.send_event(ARGV[0])
57
+ 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 'event_girl_client'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "event_girl_client"
8
+ spec.version = EventGirl::Client::VERSION
9
+ spec.authors = ["Susanne Dewein", "Tam Eastley"]
10
+ spec.email = ["susanne.dewein@gmail.com", "tam.eastley@gmail.com"]
11
+ spec.description = %q{Ruby client library to connect to event_girl app}
12
+ spec.summary = %q{Ruby client library to connect to event_girl app}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "activesupport", ">= 3.0", "< 4.1"
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,43 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+ require 'active_support/core_ext/class'
4
+
5
+ require 'rubygems'
6
+
7
+ module EventGirl
8
+ class Client
9
+
10
+ VERSION = '1.0.0'
11
+
12
+ cattr_accessor :api_token, :url
13
+ attr_reader :api_token, :url
14
+
15
+ def initialize(url = nil, api_token = nil)
16
+ @url = (url || self.class.url)
17
+ @api_token = (api_token || self.class.api_token).to_s
18
+ raise ArgumentError.new('No url provided.') unless @url
19
+ end
20
+
21
+ def send_event(title)
22
+ uri = URI.parse(url)
23
+
24
+ # This is all the post request stuff.
25
+ req = Net::HTTP::Post.new(uri.path)
26
+
27
+ # The request format and content type is json
28
+ req['Accept'] = "application/json"
29
+ req['Content-Type'] = "application/json"
30
+
31
+ # This takes the entered api token and title. This is what is sent. It is a HASH!
32
+ req.body = '{"api_token":"' + api_token + '","incoming_event":{"title":"' + title.to_s + '"}}'
33
+
34
+ # The request is sent via HTTP to the host and port. You also get a response
35
+ # ex: 201 (it worked)
36
+ Net::HTTP.new(uri.host, uri.port).start { |http| http.request(req) }
37
+ end
38
+
39
+ def self.configure
40
+ yield self if block_given?
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ describe EventGirl::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 'requires the event title as argument' do
47
+ expect(subject.method(:send_event).arity).to eql 1
48
+ end
49
+
50
+ it 'sends json data' do
51
+ title = 'event girl test'
52
+ json = '{"api_token":"' + subject.api_token + '","incoming_event":{"title":"' + title + '"}}'
53
+ stub_request(:post, subject.url).
54
+ with(body: json)
55
+ subject.send_event title
56
+ end
57
+
58
+ it 'sends json headers' do
59
+ stub_request(:post, subject.url).
60
+ with(
61
+ headers: {
62
+ 'Accept' => 'application/json',
63
+ 'Content-Type' => 'application/json'
64
+ }
65
+ )
66
+ subject.send_event 'event girl test'
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ Bundler.setup
4
+
5
+ require 'event_girl_client'
6
+ require 'webmock/rspec'
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: event_girl_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Susanne Dewein
8
+ - Tam Eastley
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-09-30 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '>='
19
+ - !ruby/object:Gem::Version
20
+ version: '3.0'
21
+ - - <
22
+ - !ruby/object:Gem::Version
23
+ version: '4.1'
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ requirements:
28
+ - - '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '3.0'
31
+ - - <
32
+ - !ruby/object:Gem::Version
33
+ version: '4.1'
34
+ - !ruby/object:Gem::Dependency
35
+ name: bundler
36
+ requirement: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ type: :development
42
+ prerelease: false
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ - !ruby/object:Gem::Dependency
49
+ name: rspec
50
+ requirement: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '2.14'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '2.14'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ type: :development
70
+ prerelease: false
71
+ version_requirements: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ - !ruby/object:Gem::Dependency
77
+ name: webmock
78
+ requirement: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ type: :development
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ description: Ruby client library to connect to event_girl app
91
+ email:
92
+ - susanne.dewein@gmail.com
93
+ - tam.eastley@gmail.com
94
+ executables:
95
+ - event_girl
96
+ extensions: []
97
+ extra_rdoc_files: []
98
+ files:
99
+ - .gitignore
100
+ - .ruby-gemset
101
+ - .ruby-version
102
+ - Gemfile
103
+ - LICENSE.txt
104
+ - README.md
105
+ - Rakefile
106
+ - bin/event_girl
107
+ - event_girl_client.gemspec
108
+ - lib/event_girl_client.rb
109
+ - spec/client_spec.rb
110
+ - spec/spec_helper.rb
111
+ homepage: ''
112
+ licenses:
113
+ - MIT
114
+ metadata: {}
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - '>='
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project:
131
+ rubygems_version: 2.0.3
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: Ruby client library to connect to event_girl app
135
+ test_files:
136
+ - spec/client_spec.rb
137
+ - spec/spec_helper.rb