iv-plurk 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.overcommit.yml +22 -0
- data/.rspec +3 -0
- data/.rubocop.yml +12 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Dockerfile +14 -0
- data/Gemfile +8 -0
- data/README.md +39 -0
- data/Rakefile +29 -0
- data/bin/console +11 -0
- data/bin/setup +8 -0
- data/exe/iv-plurk +44 -0
- data/iv-plurk.gemspec +38 -0
- data/lib/iv/plurk.rb +10 -0
- data/lib/iv/plurk/base.rb +18 -0
- data/lib/iv/plurk/client.rb +44 -0
- data/lib/iv/plurk/command_option.rb +57 -0
- data/lib/iv/plurk/credential.rb +35 -0
- data/lib/iv/plurk/direct_callable.rb +27 -0
- data/lib/iv/plurk/realtime.rb +38 -0
- data/lib/iv/plurk/request.rb +51 -0
- data/lib/iv/plurk/signature.rb +59 -0
- data/lib/iv/plurk/version.rb +7 -0
- data/lib/iv/plurk/webhook.rb +63 -0
- metadata +181 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cac6f5ef3f7118ee6ff321b99a70036967d12a9a14d06ca16b421ad5c55f68f1
|
4
|
+
data.tar.gz: d41019a794c150344c8d13580dd4a9d913f5563cdef493819a7baf4a5dcd4406
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 420187b26895a4f2236e7451706b84e066734712dc333d5a53c38b8a020926e0e362816157f8b5aa632d40c2c6a8a7dcdd4933b6741d891e3816d08ec79dccb1
|
7
|
+
data.tar.gz: faf7b02956b2e210f486180d3392eeecbfd96fce2087bae55dcda580d3c31e548f96cf858c25ed83f5063088e4b05920898665a0f7729b5c4d0d7a609f71f011
|
data/.gitignore
ADDED
data/.overcommit.yml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
PreCommit:
|
2
|
+
AuthorName:
|
3
|
+
enabled: false
|
4
|
+
RuboCop:
|
5
|
+
enabled: true
|
6
|
+
on_warn: fail # Treat all warnings as failures
|
7
|
+
TrailingWhitespace:
|
8
|
+
enabled: true
|
9
|
+
exclude:
|
10
|
+
- '.licenses/**/*'
|
11
|
+
|
12
|
+
PrePush:
|
13
|
+
BundleAudit:
|
14
|
+
enabled: true
|
15
|
+
BundleOutdated:
|
16
|
+
enabled: true
|
17
|
+
|
18
|
+
PostCheckout:
|
19
|
+
ALL: # Special hook name that customizes all hooks of this type
|
20
|
+
quiet: true # Change all post-checkout hooks to only display output on failure
|
21
|
+
IndexTags:
|
22
|
+
enabled: true # Generate a tags file with `ctags` each time HEAD changes
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -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 elct9620@frost.tw. 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/Dockerfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
FROM ruby:2.6 AS build
|
2
|
+
|
3
|
+
ARG GEM_PKG_PATH
|
4
|
+
|
5
|
+
COPY $GEM_PKG_PATH /root
|
6
|
+
RUN gem install /root/$(basename $GEM_PKG_PATH)
|
7
|
+
|
8
|
+
FROM ruby:2.6-alpine
|
9
|
+
COPY --from=build /usr/local/bundle/bin /usr/local/bundle/bin
|
10
|
+
COPY --from=build /usr/local/bundle/extensions /usr/local/bundle/extensions
|
11
|
+
COPY --from=build /usr/local/bundle/gems /usr/local/bundle/gems
|
12
|
+
COPY --from=build /usr/local/bundle/specifications /usr/local/bundle/specifications
|
13
|
+
|
14
|
+
ENTRYPOINT ["iv-plurk"]
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Iv::Plurk
|
2
|
+
|
3
|
+
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/iv/plurk`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'iv-plurk'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install iv-plurk
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
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.
|
30
|
+
|
31
|
+
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).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/iv-plurk. 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.
|
36
|
+
|
37
|
+
## Code of Conduct
|
38
|
+
|
39
|
+
Everyone interacting in the Iv::Plurk project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/iv-plurk/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
7
|
+
|
8
|
+
task default: :spec
|
9
|
+
|
10
|
+
# Docker support
|
11
|
+
DOCKER_IMAGE_NAME = 'elct9620/iv-plurk'
|
12
|
+
|
13
|
+
namespace :docker do
|
14
|
+
task :build do
|
15
|
+
path = Pathname.new Bundler::GemHelper.new.build_gem
|
16
|
+
path = path.relative_path_from Pathname.pwd
|
17
|
+
version = Bundler::GemHelper.gemspec.version.to_s
|
18
|
+
cmd = "docker build -t #{DOCKER_IMAGE_NAME} --build-arg GEM_PKG_PATH=#{path} ."
|
19
|
+
sh(cmd)
|
20
|
+
sh("docker tag #{DOCKER_IMAGE_NAME} #{DOCKER_IMAGE_NAME}:#{version}")
|
21
|
+
end
|
22
|
+
|
23
|
+
task release: [:build] do
|
24
|
+
version = Bundler::GemHelper.gemspec.version.to_s
|
25
|
+
cmd = "docker push #{DOCKER_IMAGE_NAME}"
|
26
|
+
sh(cmd)
|
27
|
+
sh("#{cmd}:#{version}")
|
28
|
+
end
|
29
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "iv/plurk"
|
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
|
data/bin/setup
ADDED
data/exe/iv-plurk
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'net/http'
|
5
|
+
require 'oj'
|
6
|
+
|
7
|
+
require 'iv/plurk'
|
8
|
+
require 'iv/plurk/command_option'
|
9
|
+
require 'iv/plurk/webhook'
|
10
|
+
|
11
|
+
Oj.default_options = { mode: :rails }
|
12
|
+
|
13
|
+
# TODO: Wrapper into class
|
14
|
+
option = IV::Plurk::CommandOption.load
|
15
|
+
raise 'Webhook URL not configured' if option.webhook_url.nil?
|
16
|
+
|
17
|
+
credential = IV::Plurk::Credential.new(
|
18
|
+
consumer_key: option.consumer_key,
|
19
|
+
consumer_secret: option.consumer_secret,
|
20
|
+
oauth_token: option.oauth_token,
|
21
|
+
oauth_secret: option.oauth_secret
|
22
|
+
)
|
23
|
+
|
24
|
+
client = IV::Plurk::Client.new(credential)
|
25
|
+
|
26
|
+
continue = true
|
27
|
+
|
28
|
+
Signal.trap(:TERM) { continue = false }
|
29
|
+
Signal.trap(:INT) { continue = false }
|
30
|
+
|
31
|
+
webhook = IV::Plurk::Webhook.new(option.webhook_url)
|
32
|
+
webhook.start
|
33
|
+
|
34
|
+
puts 'Starting subscribe timeline'
|
35
|
+
|
36
|
+
IV::Plurk.use(client) do
|
37
|
+
IV::Plurk::Realtime.subscribe do |res|
|
38
|
+
puts 'Receive new Plurk events'
|
39
|
+
webhook.enqueue(res.fetch('data', []))
|
40
|
+
continue
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
puts 'Bye!'
|
data/iv-plurk.gemspec
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'iv/plurk/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'iv-plurk'
|
9
|
+
spec.version = IV::Plurk::VERSION
|
10
|
+
spec.authors = ['蒼時弦也']
|
11
|
+
spec.email = ['elct9620@frost.tw']
|
12
|
+
|
13
|
+
spec.summary = 'Convert Plurk realtime timeline and media to webhook'
|
14
|
+
spec.description = 'Convert Plurk realtime timeline and media to webhook'
|
15
|
+
spec.homepage = 'https://github.com/elct9620/iv-plurk'
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the
|
19
|
+
# RubyGem that have been added into git.
|
20
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
21
|
+
`git ls-files -z`
|
22
|
+
.split("\x0")
|
23
|
+
.reject { |f| f.match(%r{^(test|spec|features)/}) }
|
24
|
+
end
|
25
|
+
spec.bindir = 'exe'
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ['lib']
|
28
|
+
|
29
|
+
spec.add_dependency 'oj'
|
30
|
+
|
31
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
32
|
+
spec.add_development_dependency 'bundler-audit'
|
33
|
+
spec.add_development_dependency 'overcommit'
|
34
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
35
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
36
|
+
spec.add_development_dependency 'rubocop', '~> 0.60.0'
|
37
|
+
spec.add_development_dependency 'simplecov'
|
38
|
+
end
|
data/lib/iv/plurk.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'iv/plurk/version'
|
4
|
+
require 'iv/plurk/credential'
|
5
|
+
require 'iv/plurk/signature'
|
6
|
+
require 'iv/plurk/request'
|
7
|
+
require 'iv/plurk/client'
|
8
|
+
require 'iv/plurk/direct_callable'
|
9
|
+
require 'iv/plurk/realtime'
|
10
|
+
require 'iv/plurk/base'
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module IV
|
4
|
+
# The Plurk Client
|
5
|
+
module Plurk
|
6
|
+
class << self
|
7
|
+
attr_accessor :current
|
8
|
+
|
9
|
+
def use(client = Client.default, &_block)
|
10
|
+
current = Plurk.current
|
11
|
+
Plurk.current = client
|
12
|
+
res = yield
|
13
|
+
Plurk.current = current
|
14
|
+
res
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module IV
|
4
|
+
module Plurk
|
5
|
+
# The Abstract Plurk client
|
6
|
+
class Client
|
7
|
+
class << self
|
8
|
+
def default
|
9
|
+
@default ||= new(Credential.new)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
ENDPOINT = 'https://www.plurk.com/APP/%<path>s'
|
14
|
+
|
15
|
+
def initialize(credential)
|
16
|
+
@credential = credential
|
17
|
+
end
|
18
|
+
|
19
|
+
def get(path, params = {})
|
20
|
+
Request.new(
|
21
|
+
@credential,
|
22
|
+
'GET',
|
23
|
+
URI(format(ENDPOINT, path: path)),
|
24
|
+
params.merge(oauth_params)
|
25
|
+
).start!
|
26
|
+
end
|
27
|
+
|
28
|
+
# TODO: Support Other HTTP Request
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def oauth_params
|
33
|
+
{
|
34
|
+
oauth_consumer_key: @credential.consumer_key,
|
35
|
+
oauth_nonce: Random.rand(100_000).to_s,
|
36
|
+
oauth_signature_method: 'HMAC-SHA1',
|
37
|
+
oauth_timestamp: Time.now.to_i,
|
38
|
+
oauth_token: @credential.oauth_token,
|
39
|
+
oauth_version: '1.0'
|
40
|
+
}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
|
5
|
+
module IV
|
6
|
+
module Plurk
|
7
|
+
# Webhook command line
|
8
|
+
class CommandOption < OptionParser
|
9
|
+
class << self
|
10
|
+
def load
|
11
|
+
new.parse!(ARGV)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_accessor :consumer_key, :consumer_secret,
|
16
|
+
:oauth_token, :oauth_secret,
|
17
|
+
:webhook_url
|
18
|
+
|
19
|
+
def initialize
|
20
|
+
super
|
21
|
+
|
22
|
+
@program_name = 'IV-Plurk'
|
23
|
+
self.banner = 'Illustrator Vision - Plurk Watcher'
|
24
|
+
|
25
|
+
configure_consumer
|
26
|
+
configure_token
|
27
|
+
on('-w', '--webhook URL', :REQUIRED,
|
28
|
+
'Webhook URL', method(:webhook_url=))
|
29
|
+
end
|
30
|
+
|
31
|
+
def parse!(args)
|
32
|
+
super
|
33
|
+
self
|
34
|
+
end
|
35
|
+
|
36
|
+
def version
|
37
|
+
VERSION
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def configure_consumer
|
43
|
+
on('-k', '--consumer_key [KEY]',
|
44
|
+
'Plurk Consumer Key', method(:consumer_key=))
|
45
|
+
on('-s', '--consumer_secret [SECRET]',
|
46
|
+
'Plurk Consumer Secret', method(:consumer_secret=))
|
47
|
+
end
|
48
|
+
|
49
|
+
def configure_token
|
50
|
+
on('-t', '--token [TOKEN]',
|
51
|
+
'Plurk OAuth token', method(:oauth_token=))
|
52
|
+
on('-S', '--secret [SECRET]',
|
53
|
+
'Plurk OAuth secret', method(:oauth_secret=))
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module IV
|
4
|
+
module Plurk
|
5
|
+
# The configure for iv-plurk
|
6
|
+
class Credential
|
7
|
+
attr_accessor :consumer_key, :consumer_secret,
|
8
|
+
:oauth_token, :oauth_secret
|
9
|
+
|
10
|
+
# TODO: Support normal OAuth flow
|
11
|
+
def initialize(
|
12
|
+
consumer_key: nil, consumer_secret: nil,
|
13
|
+
oauth_token: nil, oauth_secret: nil
|
14
|
+
)
|
15
|
+
@consumer_key = consumer_key || ENV['PLURK_CONSUMER_KEY']
|
16
|
+
@consumer_secret = consumer_secret || ENV['PLURK_CONSUMER_SECRET']
|
17
|
+
@oauth_token = oauth_token || ENV['PLURK_OAUTH_TOKEN']
|
18
|
+
@oauth_secret = oauth_secret || ENV['PLURK_OAUTH_SECRET']
|
19
|
+
end
|
20
|
+
|
21
|
+
def satisfied?
|
22
|
+
return false if @consumer_key.nil?
|
23
|
+
return false if @consumer_secret.nil?
|
24
|
+
return false if @oauth_token.nil?
|
25
|
+
return false if @oauth_secret.nil?
|
26
|
+
|
27
|
+
true
|
28
|
+
end
|
29
|
+
|
30
|
+
def hmac_key
|
31
|
+
@hmac_key ||= "#{@consumer_secret}&#{@oauth_secret}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module IV
|
4
|
+
module Plurk
|
5
|
+
# Define class method for API class
|
6
|
+
module DirectCallable
|
7
|
+
# :nodoc:
|
8
|
+
module ClassMethods
|
9
|
+
def respond_to_missing?(name)
|
10
|
+
super
|
11
|
+
end
|
12
|
+
|
13
|
+
def method_missing(name, *args, &block)
|
14
|
+
if instance_methods.include?(name.to_sym)
|
15
|
+
return new(Plurk.current).send(name, *args, &block)
|
16
|
+
end
|
17
|
+
|
18
|
+
super
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.included(klass)
|
23
|
+
klass.extend ClassMethods
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'oj'
|
4
|
+
|
5
|
+
module IV
|
6
|
+
module Plurk
|
7
|
+
# The realtime API
|
8
|
+
class Realtime
|
9
|
+
COMET_RULE = /CometChannel\.scriptCallback\((.*)\)/.freeze
|
10
|
+
|
11
|
+
include DirectCallable
|
12
|
+
|
13
|
+
Channel = Struct.new(:channel, :server)
|
14
|
+
|
15
|
+
def initialize(client = nil)
|
16
|
+
@client = client || Plurk.current
|
17
|
+
end
|
18
|
+
|
19
|
+
def channel
|
20
|
+
res = @client.get('Realtime/getUserChannel')
|
21
|
+
json = Oj.load(res.body)
|
22
|
+
Channel.new(
|
23
|
+
json['channel_name'],
|
24
|
+
json['comet_server']
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
def subscribe(&_block)
|
29
|
+
continue = true
|
30
|
+
while continue
|
31
|
+
Signal.trap(:INT) { return }
|
32
|
+
res = Net::HTTP.get(URI(channel.server))
|
33
|
+
continue = yield Oj.load(res[COMET_RULE, 1])
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module IV
|
4
|
+
module Plurk
|
5
|
+
# The API Request wrapper
|
6
|
+
class Request
|
7
|
+
attr_reader :credential, :method, :uri, :params
|
8
|
+
|
9
|
+
def initialize(credential, method, uri, params = {})
|
10
|
+
@credential = credential
|
11
|
+
@method = method.to_s.upcase
|
12
|
+
@uri = uri
|
13
|
+
@params = params
|
14
|
+
end
|
15
|
+
|
16
|
+
def signature
|
17
|
+
@signature ||= Signature.sign!(self)
|
18
|
+
end
|
19
|
+
|
20
|
+
def start!
|
21
|
+
Net::HTTP.start(uri.host, uri.port, use_ssl: ssl?) do |http|
|
22
|
+
http.request(signed_request)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def ssl?
|
27
|
+
uri.scheme == 'https'
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def signed_request
|
33
|
+
@signed_request ||= http_class.new(signed_uri)
|
34
|
+
end
|
35
|
+
|
36
|
+
def signed_uri
|
37
|
+
uri = @uri.clone
|
38
|
+
uri.query =
|
39
|
+
URI.encode_www_form(@params.merge(oauth_signature: signature))
|
40
|
+
uri
|
41
|
+
end
|
42
|
+
|
43
|
+
def http_class
|
44
|
+
@http_class ||=
|
45
|
+
Net::HTTP.const_get(
|
46
|
+
@method.downcase.sub(/^./, &:upcase)
|
47
|
+
)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'base64'
|
4
|
+
require 'openssl'
|
5
|
+
require 'cgi'
|
6
|
+
|
7
|
+
module IV
|
8
|
+
module Plurk
|
9
|
+
# Signature the request
|
10
|
+
class Signature
|
11
|
+
class << self
|
12
|
+
def sign!(request)
|
13
|
+
new(request).sign!
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(request)
|
18
|
+
@request = request
|
19
|
+
end
|
20
|
+
|
21
|
+
def sign!
|
22
|
+
signature
|
23
|
+
end
|
24
|
+
|
25
|
+
def signed?
|
26
|
+
@request.uri.query&.include?('oauth_signature')
|
27
|
+
end
|
28
|
+
|
29
|
+
def base
|
30
|
+
@base ||= "#{@request.method}&" \
|
31
|
+
"#{escaped_endpoint}&" \
|
32
|
+
"#{escaped_query}"
|
33
|
+
end
|
34
|
+
|
35
|
+
def signature
|
36
|
+
@signature ||=
|
37
|
+
Base64.encode64(
|
38
|
+
OpenSSL::HMAC.digest(
|
39
|
+
'sha1', @request.credential.hmac_key, base
|
40
|
+
)
|
41
|
+
).chomp
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def escaped_endpoint
|
47
|
+
@escaped_endpoint ||=
|
48
|
+
CGI.escape(@request.uri.to_s)
|
49
|
+
end
|
50
|
+
|
51
|
+
def escaped_query
|
52
|
+
@escaped_query ||=
|
53
|
+
CGI.escape(
|
54
|
+
URI.encode_www_form(@request.params)
|
55
|
+
)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module IV
|
4
|
+
module Plurk
|
5
|
+
# Send plurk data to target url
|
6
|
+
class Webhook
|
7
|
+
attr_reader :uri, :thread
|
8
|
+
|
9
|
+
def initialize(url)
|
10
|
+
@uri = URI(url)
|
11
|
+
# TODO: Add Worker Support
|
12
|
+
@thread = nil
|
13
|
+
@mutex = Mutex.new
|
14
|
+
|
15
|
+
@queue = Queue.new
|
16
|
+
@stop = false
|
17
|
+
|
18
|
+
Signal.trap(:INT) { stop! }
|
19
|
+
end
|
20
|
+
|
21
|
+
def enqueue(data)
|
22
|
+
ensure_worker
|
23
|
+
@queue << data
|
24
|
+
end
|
25
|
+
|
26
|
+
def ssl?
|
27
|
+
@uri.scheme == 'https'
|
28
|
+
end
|
29
|
+
|
30
|
+
def stop!
|
31
|
+
@stop = true
|
32
|
+
end
|
33
|
+
|
34
|
+
def start
|
35
|
+
@stop = false
|
36
|
+
ensure_worker
|
37
|
+
end
|
38
|
+
|
39
|
+
def ensure_worker
|
40
|
+
return if @stop
|
41
|
+
return unless @thread.nil?
|
42
|
+
|
43
|
+
@mutex.synchronize do
|
44
|
+
@thread = Thread.new do
|
45
|
+
submit(@queue.shift) until @stop
|
46
|
+
@thread = nil
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def submit(data)
|
54
|
+
req = Net::HTTP::Post.new(uri)
|
55
|
+
req.body = Oj.dump(data)
|
56
|
+
Net::HTTP
|
57
|
+
.start(@uri.host, @uri.port, use_ssl: ssl?) do |http|
|
58
|
+
http.request(req)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
metadata
ADDED
@@ -0,0 +1,181 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: iv-plurk
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- 蒼時弦也
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-03-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: oj
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler-audit
|
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: overcommit
|
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
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.60.0
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.60.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: simplecov
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: Convert Plurk realtime timeline and media to webhook
|
126
|
+
email:
|
127
|
+
- elct9620@frost.tw
|
128
|
+
executables:
|
129
|
+
- iv-plurk
|
130
|
+
extensions: []
|
131
|
+
extra_rdoc_files: []
|
132
|
+
files:
|
133
|
+
- ".gitignore"
|
134
|
+
- ".overcommit.yml"
|
135
|
+
- ".rspec"
|
136
|
+
- ".rubocop.yml"
|
137
|
+
- ".travis.yml"
|
138
|
+
- CODE_OF_CONDUCT.md
|
139
|
+
- Dockerfile
|
140
|
+
- Gemfile
|
141
|
+
- README.md
|
142
|
+
- Rakefile
|
143
|
+
- bin/console
|
144
|
+
- bin/setup
|
145
|
+
- exe/iv-plurk
|
146
|
+
- iv-plurk.gemspec
|
147
|
+
- lib/iv/plurk.rb
|
148
|
+
- lib/iv/plurk/base.rb
|
149
|
+
- lib/iv/plurk/client.rb
|
150
|
+
- lib/iv/plurk/command_option.rb
|
151
|
+
- lib/iv/plurk/credential.rb
|
152
|
+
- lib/iv/plurk/direct_callable.rb
|
153
|
+
- lib/iv/plurk/realtime.rb
|
154
|
+
- lib/iv/plurk/request.rb
|
155
|
+
- lib/iv/plurk/signature.rb
|
156
|
+
- lib/iv/plurk/version.rb
|
157
|
+
- lib/iv/plurk/webhook.rb
|
158
|
+
homepage: https://github.com/elct9620/iv-plurk
|
159
|
+
licenses: []
|
160
|
+
metadata: {}
|
161
|
+
post_install_message:
|
162
|
+
rdoc_options: []
|
163
|
+
require_paths:
|
164
|
+
- lib
|
165
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
166
|
+
requirements:
|
167
|
+
- - ">="
|
168
|
+
- !ruby/object:Gem::Version
|
169
|
+
version: '0'
|
170
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
171
|
+
requirements:
|
172
|
+
- - ">="
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
version: '0'
|
175
|
+
requirements: []
|
176
|
+
rubyforge_project:
|
177
|
+
rubygems_version: 2.7.6
|
178
|
+
signing_key:
|
179
|
+
specification_version: 4
|
180
|
+
summary: Convert Plurk realtime timeline and media to webhook
|
181
|
+
test_files: []
|