skype_bot 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/README.md +36 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/skype_bot/activity.rb +22 -0
- data/lib/skype_bot/attachment.rb +0 -0
- data/lib/skype_bot/auth.rb +35 -0
- data/lib/skype_bot/config.rb +11 -0
- data/lib/skype_bot/parser.rb +22 -0
- data/lib/skype_bot/version.rb +3 -0
- data/lib/skype_bot.rb +22 -0
- data/skype_bot.gemspec +27 -0
- metadata +131 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4d2a45e74703578a6920b8b3757ca6e714032744
|
4
|
+
data.tar.gz: 21075dafd0c9ba5496b3b03e05392d7d7043635b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6a08546f4696ab76210fb3d95d5f6dcf289009ae4e26128a977242f93c51ce113354e2ae9709279e1d56806b3877c1096b4ac7e48a059bc036d2524cdc694742
|
7
|
+
data.tar.gz: 36675722c455ec4c7aed57d5564e6818bf6cfea5e6eee4c8e91529ee8a2b89e737e3e551f8326b4e44f52e5024054fd7fd63da195d59dd3070ba6f7801ef40ae
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at sugiacupit@gmail.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# SkypeBot
|
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/skype_bot`. 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 'skype_bot'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install skype_bot
|
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]/skype_bot. 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
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "skype_bot"
|
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
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
module SkypeBot
|
2
|
+
module Activity
|
3
|
+
extend self
|
4
|
+
|
5
|
+
CONVERSATION_URL = 'https://apis.skype.com/v2/conversations'
|
6
|
+
|
7
|
+
def text_message(uid, content)
|
8
|
+
token = Auth.get_token
|
9
|
+
body = { message: { content: content } }.to_json
|
10
|
+
headers = { Authorization: "Bearer #{token}", 'Content-Type': 'application/json' }
|
11
|
+
url = activity_url(uid)
|
12
|
+
|
13
|
+
Typhoeus.post(url, body: body, headers: headers)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def activity_url(uid)
|
19
|
+
"#{CONVERSATION_URL}/#{uid}/activities"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
File without changes
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module SkypeBot
|
2
|
+
module Auth
|
3
|
+
extend self
|
4
|
+
|
5
|
+
OAUTH_URL = 'https://login.microsoftonline.com/common/oauth2/v2.0/token'
|
6
|
+
|
7
|
+
# NOTE: minus 5 seconds to prevent token expire
|
8
|
+
def get_token
|
9
|
+
if @token && @valid_until && @valid_until > Time.current - 5.seconds
|
10
|
+
@token
|
11
|
+
else
|
12
|
+
renew_token
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def renew_token
|
17
|
+
response = Typhoeus.post(OAUTH_URL, body: auth_params)
|
18
|
+
response_body = JSON.parse(response.body)
|
19
|
+
|
20
|
+
@valid_until = Time.current + response_body['expires_in'].seconds
|
21
|
+
@token = response_body['access_token']
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def auth_params
|
27
|
+
{
|
28
|
+
client_id: Config.app_id,
|
29
|
+
client_secret: Config.app_secret,
|
30
|
+
grant_type: 'client_credentials',
|
31
|
+
scope: Config.scope
|
32
|
+
}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module SkypeBot
|
2
|
+
class Parser
|
3
|
+
attr_accessor :payload
|
4
|
+
|
5
|
+
def initialize(data)
|
6
|
+
@payload = payload['_json']
|
7
|
+
end
|
8
|
+
|
9
|
+
def execute
|
10
|
+
payload.map do |event|
|
11
|
+
{
|
12
|
+
type: event['activity'].underscore,
|
13
|
+
from: event['from'],
|
14
|
+
display_name: event['fromDisplayName'],
|
15
|
+
to: event['to'],
|
16
|
+
time: Time.parse(event['time']),
|
17
|
+
content: event['content'] }
|
18
|
+
}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/skype_bot.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'typhoeus'
|
2
|
+
|
3
|
+
require 'skype_bot/activity'
|
4
|
+
require 'skype_bot/auth'
|
5
|
+
require 'skype_bot/config'
|
6
|
+
require 'skype_bot/version'
|
7
|
+
|
8
|
+
module SkypeBot
|
9
|
+
extend self
|
10
|
+
|
11
|
+
def configure
|
12
|
+
yield(Config) if block_given?
|
13
|
+
end
|
14
|
+
|
15
|
+
def message(uid, content)
|
16
|
+
Activity.text_message(uid, content)
|
17
|
+
end
|
18
|
+
|
19
|
+
def parser(data)
|
20
|
+
Parser.new(data).execute
|
21
|
+
end
|
22
|
+
end
|
data/skype_bot.gemspec
ADDED
@@ -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 'skype_bot/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "skype_bot"
|
8
|
+
spec.version = SkypeBot::VERSION
|
9
|
+
spec.authors = ["MQuy"]
|
10
|
+
spec.email = ["sugiacupit@gmail.com"]
|
11
|
+
spec.homepage = "https://github.com/Coffa/skype_bot"
|
12
|
+
|
13
|
+
spec.summary = %q{Write a short summary, because Rubygems requires one.}
|
14
|
+
spec.description = %q{Write a longer description or delete this line.}
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
24
|
+
|
25
|
+
spec.add_dependency 'typhoeus', '~> 1.0'
|
26
|
+
spec.add_dependency 'faraday', '~> 0.9.2'
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: skype_bot
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- MQuy
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-24 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.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
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: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: typhoeus
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: faraday
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.9.2
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.9.2
|
83
|
+
description: Write a longer description or delete this line.
|
84
|
+
email:
|
85
|
+
- sugiacupit@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".travis.yml"
|
93
|
+
- CODE_OF_CONDUCT.md
|
94
|
+
- Gemfile
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- bin/console
|
98
|
+
- bin/setup
|
99
|
+
- lib/skype_bot.rb
|
100
|
+
- lib/skype_bot/activity.rb
|
101
|
+
- lib/skype_bot/attachment.rb
|
102
|
+
- lib/skype_bot/auth.rb
|
103
|
+
- lib/skype_bot/config.rb
|
104
|
+
- lib/skype_bot/parser.rb
|
105
|
+
- lib/skype_bot/version.rb
|
106
|
+
- skype_bot.gemspec
|
107
|
+
homepage: https://github.com/Coffa/skype_bot
|
108
|
+
licenses: []
|
109
|
+
metadata: {}
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options: []
|
112
|
+
require_paths:
|
113
|
+
- lib
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
requirements: []
|
125
|
+
rubyforge_project:
|
126
|
+
rubygems_version: 2.5.1
|
127
|
+
signing_key:
|
128
|
+
specification_version: 4
|
129
|
+
summary: Write a short summary, because Rubygems requires one.
|
130
|
+
test_files: []
|
131
|
+
has_rdoc:
|