pushit-ruby 0.0.1

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: c619114429972a027a0a17650aa7e7fdfe5dce0b
4
+ data.tar.gz: bc97452ef64335aee2ddac7b112772f575c667cb
5
+ SHA512:
6
+ metadata.gz: c1899ad5c6d4338eb712e11254d41c32f0afd89210c65c25bfff049b3636a044fef79bc41e2a205d9ba79aec10eb4d3280ee253a2044f7e7471542d6818b65dc
7
+ data.tar.gz: 6b8c469548cd05d455695406d2131e6d94667337b6bd1f98a0101f4bef07954d89490de45412065d9860224c195b09ebccb05ba9d31bfff0c2b997c0c92a89f8
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ .rvmrc
12
+ *.so
13
+ *.o
14
+ *.a
15
+ mkmf.log
16
+ *.gem
17
+ .ruby-gemset
18
+ .ruby-version
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in getyourguide.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem 'pry'
8
+ gem 'pry-byebug'
9
+ end
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,34 @@
1
+ module Pushit
2
+ class Channel
3
+ require 'openssl'
4
+ require 'multi_json'
5
+
6
+ def initialize(channel_name, options = {})
7
+ options = {
8
+ :scheme => 'https',
9
+ :host => 'pushit-beta.herokuapp.com'
10
+ }.merge(options)
11
+
12
+ @channel_name = channel_name
13
+
14
+ @scheme, @host, @port = options.values_at(
15
+ :scheme, :host, :port
16
+ )
17
+ end
18
+
19
+ def post(event, data = {})
20
+ Request.new(:post, url(event)).post(data)
21
+ end
22
+
23
+ private
24
+
25
+ def url(event)
26
+ URI::HTTPS.build({
27
+ :scheme => @scheme,
28
+ :host => @host,
29
+ :port => @port,
30
+ :path => "/publish/#{@channel_name}/#{event}"
31
+ })
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,44 @@
1
+ module Pushit
2
+ class Request
3
+ require 'net/http'
4
+
5
+ def initialize(type, url)
6
+ @type = type
7
+ @url = url
8
+ @head = {}
9
+ @head['Content-Type'] = 'application/json'
10
+ end
11
+
12
+ def post(body)
13
+ response = Net::HTTP.post_form(@url, body)
14
+
15
+ handle_response(response.code.to_i, response.body)
16
+ end
17
+
18
+ private
19
+
20
+ def handle_response(status_code, body)
21
+ case status_code
22
+ when 200
23
+ return symbolize_first_level(MultiJson.decode(body))
24
+ when 202
25
+ return true
26
+ when 400
27
+ raise Error, "Bad request: #{body}"
28
+ when 401
29
+ raise AuthenticationError, body
30
+ when 404
31
+ raise Error, "404 Not found (#{@url.path})"
32
+ else
33
+ raise Error, "Unknown error (status code #{status_code}): #{body}"
34
+ end
35
+ end
36
+
37
+ def symbolize_first_level(hash)
38
+ hash.inject({}) do |result, (key, value)|
39
+ result[key.to_sym] = value
40
+ result
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,3 @@
1
+ module Pushit
2
+ VERSION = "0.0.1"
3
+ end
data/lib/pushit.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "pushit/version"
2
+ require "pushit/channel"
3
+ require "pushit/request"
4
+
5
+ module Pushit
6
+ end
data/pushit.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ require File.expand_path('../lib/pushit/version', __FILE__)
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = 'pushit-ruby'
6
+ spec.version = Pushit::VERSION
7
+ spec.authors = ['Rémi Delhaye']
8
+ spec.email = ['contact@rdlh.io']
9
+ spec.summary = 'A simple ruby client for Pushit App'
10
+ spec.description = 'A simple ruby client for Pushit App'
11
+ spec.homepage = 'https://github.com/pushit-app/pushit-ruby'
12
+ spec.license = 'MIT'
13
+ spec.required_ruby_version = '~> 2.0'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency 'bundler', '~> 1.7'
21
+ spec.add_development_dependency 'rake', '~> 10.0'
22
+
23
+ spec.add_runtime_dependency 'httpclient', '~> 2.3', '>= 2.3.1'
24
+ spec.add_runtime_dependency 'multi_json', '~> 1.0'
25
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pushit-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Rémi Delhaye
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: httpclient
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.3'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 2.3.1
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '2.3'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 2.3.1
61
+ - !ruby/object:Gem::Dependency
62
+ name: multi_json
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '1.0'
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '1.0'
75
+ description: A simple ruby client for Pushit App
76
+ email:
77
+ - contact@rdlh.io
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - ".gitignore"
83
+ - Gemfile
84
+ - Rakefile
85
+ - lib/pushit.rb
86
+ - lib/pushit/channel.rb
87
+ - lib/pushit/request.rb
88
+ - lib/pushit/version.rb
89
+ - pushit.gemspec
90
+ homepage: https://github.com/pushit-app/pushit-ruby
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '2.0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.4.6
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: A simple ruby client for Pushit App
114
+ test_files: []