nagareboshi 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 47f60d96ae02faa674171da584cb3717433f7a79
4
+ data.tar.gz: 8fb039a4606b3819b10e8b002b9ceb2139da2c92
5
+ SHA512:
6
+ metadata.gz: 2c18eaaafdaa43e12b1baeb4d26c445353e789177ab678b2b8d0dba2875168d86fb9b608dcac82b71e448aa8099fb58d7808d59d1f54c6f22bba1d12ca97dcb5
7
+ data.tar.gz: 4b4f892042c24cbcef3f4e7b89cfcbd27e19407290acead54792d2017e9a15dccdd63ac05f1ac45d3c4d69c350e517ea03a821d02db154bd1d44f5c0abd50ebb
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/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in nagareboshi.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 TODO: Write your name
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,42 @@
1
+ # Nagareboshi
2
+
3
+ Ruby PubSubHubbub Client
4
+
5
+ http://code.google.com/p/pubsubhubbub
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'nagareboshi'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install nagareboshi
20
+
21
+ ## Usage
22
+
23
+ Ruby settings
24
+
25
+ Ngareboshi.configure do |config|
26
+ config.send = true
27
+ end
28
+
29
+ Rails settings send to production only
30
+
31
+ Ngareboshi.configure do |config|
32
+ config.send = Rails.env.production?
33
+ end
34
+
35
+ send http://example.com/
36
+
37
+ Nagareboshi::Sender.publish("http://example.com/")
38
+
39
+ send many url
40
+
41
+ Nagareboshi::Sender.publish(["http://example.com/", "http://example.com/1"])
42
+
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
data/example/sender.rb ADDED
@@ -0,0 +1,21 @@
1
+ lib = File.expand_path('../../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ require 'nagareboshi'
5
+
6
+ Nagareboshi.configure do |config|
7
+ config.send = true
8
+ # config.send = Rails.env.production? rails case setting
9
+ end
10
+
11
+ Nagareboshi::Sender.publish("http://...")
12
+ Nagareboshi::Sender.publish(["http://...", "http://..."])
13
+
14
+ # debug
15
+ Nagareboshi.configure do |config|
16
+ config.host = "localhost"
17
+ config.send = true
18
+ config.use_ssl = false
19
+ end
20
+
21
+ Nagareboshi::Sender.publish("http://...")
@@ -0,0 +1,17 @@
1
+ require 'net/http'
2
+ require 'net/https'
3
+
4
+ module Nagareboshi
5
+ module_function
6
+ def self.configure(&block)
7
+ yield(configuration)
8
+ end
9
+
10
+ def configuration
11
+ @_configuration ||= Configuration.new
12
+ end
13
+ end
14
+
15
+ require 'nagareboshi/version'
16
+ require 'nagareboshi/configuration'
17
+ require 'nagareboshi/sender'
@@ -0,0 +1,11 @@
1
+ module Nagareboshi
2
+ class Configuration
3
+ attr_accessor :host, :send, :use_ssl
4
+
5
+ def initialize
6
+ @host = "pubsubhubbub.appspot.com"
7
+ @send = false
8
+ @use_ssl = true
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,46 @@
1
+ module Nagareboshi
2
+ module Sender
3
+ class << self
4
+
5
+ def publish(urls)
6
+ urls = [urls] if urls.is_a?(String)
7
+ body = urls.map do |url|
8
+ URI.encode_www_form({'hub.mode' => 'publish', 'hub.url' => url})
9
+ end.join('&')
10
+ shooting_star(body)
11
+ end
12
+
13
+ private
14
+ def shooting_star(body)
15
+ request = Net::HTTP::Post.new(URI(uri))
16
+ request.body = body
17
+ headers.each { |k, v| request[k.to_s] = v.to_s}
18
+ ☆(request) if send?
19
+ end
20
+
21
+ def ☆(request)
22
+ http = Net::HTTP.new(Nagareboshi.configuration.host, ssl? ? 443 : 80)
23
+ http.use_ssl = ssl?
24
+ response = http.start do |http|
25
+ http.request request
26
+ end
27
+ end
28
+
29
+ def headers
30
+ {"User-Agent" => "Nagareboshi Ruby Library v#{VERSION}", "Content-Type" => "application/x-www-form-urlencoded"}
31
+ end
32
+
33
+ def send?
34
+ Nagareboshi.configuration.send == true
35
+ end
36
+
37
+ def uri
38
+ "#{ssl? ? 'https' : 'http'}://#{Nagareboshi.configuration.host}/"
39
+ end
40
+
41
+ def ssl?
42
+ Nagareboshi.configuration.use_ssl == true
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,3 @@
1
+ module Nagareboshi
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'nagareboshi/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "nagareboshi"
8
+ spec.version = Nagareboshi::VERSION
9
+ spec.authors = ["shiro16"]
10
+ spec.email = ["nyanyanyawan24@gmail.com"]
11
+ spec.description = %q{Throw URL to google pubsubhubbub}
12
+ spec.summary = %q{Throw URL to google pubsubhubbub}
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_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "webmock"
25
+ end
@@ -0,0 +1,12 @@
1
+ # coding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Nagareboshi::Configuration do
6
+ context "default instance variable" do
7
+ let(:configuration) { Nagareboshi::Configuration.new }
8
+ it { expect(configuration.host).to eq "pubsubhubbub.appspot.com" }
9
+ it { expect(configuration.send).to be_falsy }
10
+ it { expect(configuration.use_ssl).to be_truthy }
11
+ end
12
+ end
@@ -0,0 +1,98 @@
1
+ # coding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Nagareboshi::Sender do
6
+ let(:url) { "http://localhost/" }
7
+ let(:sender) { Nagareboshi::Sender }
8
+ before do
9
+ Nagareboshi.configure do |config|
10
+ config.host = "localhost"
11
+ config.send = true
12
+ config.use_ssl = false
13
+ end
14
+ stub_request(:post, url).to_return(status: 200)
15
+ end
16
+
17
+ context "publish" do
18
+ it "called shooting star" do
19
+ expect(sender).to receive(:shooting_star).with("hub.mode=publish&hub.url=test")
20
+ expect(sender.publish("test")).to be_nil
21
+ end
22
+ it "return HTTPOK" do
23
+ expect(sender.publish("test")).to be_an_instance_of(Net::HTTPOK)
24
+ end
25
+ end
26
+
27
+ describe "private methods" do
28
+ context "shooting_star" do
29
+ subject { sender.send(:shooting_star, "test") }
30
+ context "send? is true" do
31
+ it "return HTTPOK" do
32
+ expect(subject).to be_an_instance_of(Net::HTTPOK)
33
+ end
34
+
35
+ it "called ☆" do
36
+ expect(sender).to receive(:☆).with(Net::HTTP::Post)
37
+ expect(subject).to be_nil
38
+ end
39
+ end
40
+
41
+ it "send? is false" do
42
+ allow(sender).to receive(:send?).and_return(false)
43
+ expect(sender).to_not receive(:☆)
44
+ expect(subject).to be_nil
45
+ end
46
+ end
47
+
48
+ context "☆" do
49
+ subject { sender.send(:☆, Net::HTTP::Post.new(URI(url))) }
50
+ it { expect(subject).to be_an_instance_of(Net::HTTPOK) }
51
+ end
52
+
53
+ context "headers" do
54
+ subject { sender.send(:headers) }
55
+
56
+ it { expect(subject).to eq({"User-Agent" => "Nagareboshi Ruby Library v#{Nagareboshi::VERSION}", "Content-Type" => "application/x-www-form-urlencoded"}) }
57
+ end
58
+
59
+ context "send?" do
60
+ subject { sender.send(:send?) }
61
+
62
+ it "send is true" do
63
+ expect(subject).to be_truthy
64
+ end
65
+
66
+ it "send is false" do
67
+ allow(sender).to receive(:send?).and_return(false)
68
+ expect(subject).to be_falsy
69
+ end
70
+ end
71
+
72
+ context "uri" do
73
+ subject { sender.send(:uri) }
74
+
75
+ it "ssl? is true" do
76
+ allow(sender).to receive(:ssl?).and_return(true)
77
+ expect(subject).to eq "https://localhost/"
78
+ end
79
+
80
+ it "ssl? is false" do
81
+ expect(subject).to eq "http://localhost/"
82
+ end
83
+ end
84
+
85
+ context "ssl?" do
86
+ subject { sender.send(:ssl?) }
87
+
88
+ it "use_ssl is true" do
89
+ allow(Nagareboshi.configuration).to receive(:use_ssl).and_return(true)
90
+ expect(subject).to be_truthy
91
+ end
92
+
93
+ it "user_ssl is false" do
94
+ expect(subject).to be_falsy
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe Nagareboshi do
4
+ it 'should have a version number' do
5
+ expect(Nagareboshi::VERSION).to_not be_nil
6
+ end
7
+
8
+ context 'configure set host send use_ssl' do
9
+ before do
10
+ Nagareboshi.configure do |config|
11
+ config.host = 'localhost'
12
+ config.send = true
13
+ config.use_ssl = false
14
+ end
15
+ end
16
+
17
+ it { expect(Nagareboshi.configuration.host).to eq 'localhost' }
18
+ it { expect(Nagareboshi.configuration.send).to be_truthy }
19
+ it { expect(Nagareboshi.configuration.use_ssl).to be_falsy }
20
+ end
21
+ end
@@ -0,0 +1,4 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+
3
+ require 'nagareboshi'
4
+ require 'webmock/rspec'
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nagareboshi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - shiro16
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-28 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Throw URL to google pubsubhubbub
70
+ email:
71
+ - nyanyanyawan24@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - .rspec
78
+ - .travis.yml
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - example/sender.rb
84
+ - lib/nagareboshi.rb
85
+ - lib/nagareboshi/configuration.rb
86
+ - lib/nagareboshi/sender.rb
87
+ - lib/nagareboshi/version.rb
88
+ - nagareboshi.gemspec
89
+ - spec/nagareboshi/configuration_spec.rb
90
+ - spec/nagareboshi/sender_spec.rb
91
+ - spec/nagareboshi_spec.rb
92
+ - spec/spec_helper.rb
93
+ homepage: ''
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.0.3
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Throw URL to google pubsubhubbub
117
+ test_files:
118
+ - spec/nagareboshi/configuration_spec.rb
119
+ - spec/nagareboshi/sender_spec.rb
120
+ - spec/nagareboshi_spec.rb
121
+ - spec/spec_helper.rb