laziness 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +4 -4
- data/README.md +7 -1
- data/lib/laziness/api/auth.rb +1 -1
- data/lib/laziness/api/base.rb +11 -4
- data/lib/laziness/api/channels.rb +5 -5
- data/lib/laziness/api/groups.rb +13 -13
- data/lib/laziness/api/oauth.rb +11 -0
- data/lib/laziness/api/users.rb +3 -3
- data/lib/laziness/api.rb +1 -0
- data/lib/laziness/client.rb +5 -1
- data/lib/laziness/oauth.rb +4 -0
- data/lib/laziness/version.rb +1 -1
- data/lib/laziness.rb +1 -0
- data/spec/laziness/api/oauth_spec.rb +16 -0
- data/spec/support/fixtures/oauth_access.json +11 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 622956ad7a455f78936d697f1f21cd6cb62c820c
|
4
|
+
data.tar.gz: c4f4653e0dd6667d43a3ff45f8eab4063b4a1690
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ecb218a57e2978c4019167a0bb90a72ec9824612035b8e198f29ad3ea000c2f52643c001937e1fabb28ee88d2402013e31fc6517bd560db1064cdb27b6e89d4e
|
7
|
+
data.tar.gz: 738574f928528f2b953d8da1e8c2bd6e0752038bb9ff732e0ed531283c3c8693041b2159d541f1864a454645401911fd28f1576c3796c070e8b0b4eb571f086c
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
laziness (0.1.
|
4
|
+
laziness (0.1.5)
|
5
5
|
hashie
|
6
6
|
httparty
|
7
7
|
|
@@ -12,11 +12,11 @@ GEM
|
|
12
12
|
crack (0.4.2)
|
13
13
|
safe_yaml (~> 1.0.0)
|
14
14
|
diff-lcs (1.2.5)
|
15
|
-
hashie (3.4.
|
16
|
-
httparty (0.13.
|
15
|
+
hashie (3.4.2)
|
16
|
+
httparty (0.13.5)
|
17
17
|
json (~> 1.8)
|
18
18
|
multi_xml (>= 0.5.2)
|
19
|
-
json (1.8.
|
19
|
+
json (1.8.3)
|
20
20
|
multi_xml (0.5.5)
|
21
21
|
rake (10.3.2)
|
22
22
|
rspec (3.1.0)
|
data/README.md
CHANGED
@@ -96,6 +96,12 @@ client.groups.update_topic(group_id, topic) # updates the topic for the specific
|
|
96
96
|
client.auth.test # get info about a specific oauth token
|
97
97
|
```
|
98
98
|
|
99
|
+
### OAuth
|
100
|
+
|
101
|
+
```
|
102
|
+
client.oauth.access(client_id, client_secret, code, redirect_uri) # exchange api token for code
|
103
|
+
```
|
104
|
+
|
99
105
|
### Presence
|
100
106
|
|
101
107
|
### Search
|
@@ -122,6 +128,6 @@ client.users.set_active # sets the current user (defined by the access_token) as
|
|
122
128
|
## RELEASING A NEW GEM
|
123
129
|
|
124
130
|
1. Bump the VERSION in `lib/laziness/version.rb`
|
125
|
-
1. Commit changes and push to GitHub
|
126
131
|
1. run `bundle exec rake build`
|
132
|
+
1. Commit changes and push to GitHub
|
127
133
|
1. run `bundle exec rake release`
|
data/lib/laziness/api/auth.rb
CHANGED
data/lib/laziness/api/base.rb
CHANGED
@@ -3,7 +3,7 @@ module Slack
|
|
3
3
|
class Base
|
4
4
|
attr_reader :access_token
|
5
5
|
|
6
|
-
def initialize(access_token)
|
6
|
+
def initialize(access_token=nil)
|
7
7
|
@access_token = access_token
|
8
8
|
end
|
9
9
|
|
@@ -18,9 +18,16 @@ module Slack
|
|
18
18
|
nil
|
19
19
|
end
|
20
20
|
|
21
|
-
def request(method,
|
22
|
-
full_path = "#{base_path}#{path}
|
23
|
-
|
21
|
+
def request(method, path, arguments={})
|
22
|
+
full_path = "#{base_path}#{path}"
|
23
|
+
full_path = "#{full_path}?token=#{access_token}" unless access_token.nil?
|
24
|
+
arguments.each_pair do |key, value|
|
25
|
+
unless value.nil?
|
26
|
+
seperator = full_path.include?("?") ? "&" : "?"
|
27
|
+
full_path = "#{full_path}#{seperator}#{key}=#{ERB::Util.url_encode(value)}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
24
31
|
options = {
|
25
32
|
headers: {
|
26
33
|
"Accept" => "application/json",
|
@@ -2,26 +2,26 @@ module Slack
|
|
2
2
|
module API
|
3
3
|
class Channels < Base
|
4
4
|
def all(exclude_archived=false)
|
5
|
-
response = request :get,
|
5
|
+
response = request :get, 'channels.list', exclude_archived: exclude_archived ? 1 : 0
|
6
6
|
Slack::Channel.parse response, 'channels'
|
7
7
|
end
|
8
8
|
|
9
9
|
def archive(id)
|
10
|
-
with_nil_response { request :post,
|
10
|
+
with_nil_response { request :post, 'channels.archive', channel: id }
|
11
11
|
end
|
12
12
|
|
13
13
|
def create(name)
|
14
|
-
response = request :post,
|
14
|
+
response = request :post, 'channels.create', name: name
|
15
15
|
Slack::Channel.parse response, 'channel'
|
16
16
|
end
|
17
17
|
|
18
18
|
def find(id)
|
19
|
-
response = request :get,
|
19
|
+
response = request :get, 'channels.info', channel: id
|
20
20
|
Slack::Channel.parse response, 'channel'
|
21
21
|
end
|
22
22
|
|
23
23
|
def unarchive(id)
|
24
|
-
with_nil_response { request :post,
|
24
|
+
with_nil_response { request :post, 'channels.unarchive', channel: id }
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
data/lib/laziness/api/groups.rb
CHANGED
@@ -2,60 +2,60 @@ module Slack
|
|
2
2
|
module API
|
3
3
|
class Groups < Base
|
4
4
|
def all(exclude_archived=false)
|
5
|
-
response = request :get,
|
5
|
+
response = request :get, 'groups.list', exclude_archived: exclude_archived ? 1 : 0
|
6
6
|
Slack::Group.parse response, 'groups'
|
7
7
|
end
|
8
8
|
|
9
9
|
def archive(id)
|
10
|
-
with_nil_response { request :post,
|
10
|
+
with_nil_response { request :post, 'groups.archive', channel: id }
|
11
11
|
end
|
12
12
|
|
13
13
|
def close(id)
|
14
|
-
with_nil_response { request :post,
|
14
|
+
with_nil_response { request :post, 'groups.close', channel: id }
|
15
15
|
end
|
16
16
|
|
17
17
|
def copy(id)
|
18
|
-
response = request :post,
|
18
|
+
response = request :post, 'groups.createChild', channel: id
|
19
19
|
Slack::Group.parse response, 'group'
|
20
20
|
end
|
21
21
|
|
22
22
|
def create(name)
|
23
|
-
response = request :post,
|
23
|
+
response = request :post, 'groups.create', name: name
|
24
24
|
Slack::Group.parse response, 'group'
|
25
25
|
end
|
26
26
|
|
27
27
|
def find(id)
|
28
|
-
response = request :get,
|
28
|
+
response = request :get, 'groups.info', channel: id
|
29
29
|
Slack::Group.parse response, 'group'
|
30
30
|
end
|
31
31
|
|
32
32
|
def invite(id, user_id)
|
33
|
-
response = request :post,
|
33
|
+
response = request :post, 'groups.invite', channel: id, user: user_id
|
34
34
|
Slack::Group.parse response, 'group'
|
35
35
|
end
|
36
36
|
|
37
37
|
def kick(id, user_id)
|
38
|
-
with_nil_response { request :post,
|
38
|
+
with_nil_response { request :post, 'groups.kick', channel: id, user: user_id }
|
39
39
|
end
|
40
40
|
|
41
41
|
def leave(id)
|
42
|
-
with_nil_response { request :post,
|
42
|
+
with_nil_response { request :post, 'groups.leave', channel: id }
|
43
43
|
end
|
44
44
|
|
45
45
|
def open(id)
|
46
|
-
with_nil_response { request :post,
|
46
|
+
with_nil_response { request :post, 'groups.open', channel: id }
|
47
47
|
end
|
48
48
|
|
49
49
|
def unarchive(id)
|
50
|
-
with_nil_response { request :post,
|
50
|
+
with_nil_response { request :post, 'groups.unarchive', channel: id }
|
51
51
|
end
|
52
52
|
|
53
53
|
def update_purpose(id, purpose)
|
54
|
-
with_nil_response { request :post,
|
54
|
+
with_nil_response { request :post, 'groups.setPurpose', channel: id, purpose: purpose }
|
55
55
|
end
|
56
56
|
|
57
57
|
def update_topic(id, topic)
|
58
|
-
with_nil_response { request :post,
|
58
|
+
with_nil_response { request :post, 'groups.setTopic', channel: id, topic: topic }
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Slack
|
2
|
+
module API
|
3
|
+
class OAuth < Base
|
4
|
+
def access(client_id, client_secret, code, redirect_uri=nil)
|
5
|
+
response = request :get, 'oauth.access', client_id: client_id,
|
6
|
+
client_secret: client_secret, code: code, redirect_uri: redirect_uri
|
7
|
+
Slack::Auth.parse response
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/lib/laziness/api/users.rb
CHANGED
@@ -2,17 +2,17 @@ module Slack
|
|
2
2
|
module API
|
3
3
|
class Users < Base
|
4
4
|
def all
|
5
|
-
response = request :get,
|
5
|
+
response = request :get, 'users.list'
|
6
6
|
Slack::User.parse response, 'members'
|
7
7
|
end
|
8
8
|
|
9
9
|
def find(id)
|
10
|
-
response = request :get,
|
10
|
+
response = request :get, 'users.info', user: id
|
11
11
|
Slack::User.parse response, 'user'
|
12
12
|
end
|
13
13
|
|
14
14
|
def set_active
|
15
|
-
with_nil_response { request :post,
|
15
|
+
with_nil_response { request :post, 'users.setActive' }
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
data/lib/laziness/api.rb
CHANGED
data/lib/laziness/client.rb
CHANGED
@@ -2,7 +2,7 @@ module Slack
|
|
2
2
|
class Client
|
3
3
|
attr_reader :access_token
|
4
4
|
|
5
|
-
def initialize(access_token)
|
5
|
+
def initialize(access_token=nil)
|
6
6
|
@access_token = access_token
|
7
7
|
end
|
8
8
|
|
@@ -18,6 +18,10 @@ module Slack
|
|
18
18
|
@groups ||= Slack::API::Groups.new(access_token)
|
19
19
|
end
|
20
20
|
|
21
|
+
def oauth
|
22
|
+
@oauth ||= Slack::API::OAuth.new
|
23
|
+
end
|
24
|
+
|
21
25
|
def users
|
22
26
|
@users ||= Slack::API::Users.new(access_token)
|
23
27
|
end
|
data/lib/laziness/version.rb
CHANGED
data/lib/laziness.rb
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
describe Slack::API::OAuth do
|
2
|
+
subject { Slack::API::OAuth.new }
|
3
|
+
|
4
|
+
describe '.access' do
|
5
|
+
let(:client_id) { "1234" }
|
6
|
+
let(:client_secret) { "5678" }
|
7
|
+
let(:code) { "9012" }
|
8
|
+
|
9
|
+
it 'exchanges a temporary oauth code for an API access token' do
|
10
|
+
stub_slack_request :get, "oauth.access?client_id=#{client_id}&client_secret=#{client_secret}&code=#{code}", 'oauth_access.json'
|
11
|
+
|
12
|
+
oauth = subject.access client_id, client_secret, code
|
13
|
+
expect(oauth.ok).to eq true
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
{
|
2
|
+
"ok": true,
|
3
|
+
"access_token": "123456",
|
4
|
+
"scope": "incoming-webhook",
|
5
|
+
"team_name": "tour",
|
6
|
+
"incoming_webhook": {
|
7
|
+
"url": "https:\/\/tour.slack.com\/",
|
8
|
+
"channel": "#general",
|
9
|
+
"configuration_url": "https:\/\/hooks.slack.com\/services\/T1234\/1234\/"
|
10
|
+
}
|
11
|
+
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: laziness
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jamie Wright
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -61,6 +61,7 @@ files:
|
|
61
61
|
- lib/laziness/api/base.rb
|
62
62
|
- lib/laziness/api/channels.rb
|
63
63
|
- lib/laziness/api/groups.rb
|
64
|
+
- lib/laziness/api/oauth.rb
|
64
65
|
- lib/laziness/api/users.rb
|
65
66
|
- lib/laziness/auth.rb
|
66
67
|
- lib/laziness/base.rb
|
@@ -68,11 +69,13 @@ files:
|
|
68
69
|
- lib/laziness/client.rb
|
69
70
|
- lib/laziness/errors.rb
|
70
71
|
- lib/laziness/group.rb
|
72
|
+
- lib/laziness/oauth.rb
|
71
73
|
- lib/laziness/user.rb
|
72
74
|
- lib/laziness/version.rb
|
73
75
|
- spec/laziness/api/auth_spec.rb
|
74
76
|
- spec/laziness/api/channels_spec.rb
|
75
77
|
- spec/laziness/api/groups_spec.rb
|
78
|
+
- spec/laziness/api/oauth_spec.rb
|
76
79
|
- spec/laziness/api/users_spec.rb
|
77
80
|
- spec/laziness/client_spec.rb
|
78
81
|
- spec/laziness/errors_spec.rb
|
@@ -82,6 +85,7 @@ files:
|
|
82
85
|
- spec/support/fixtures/channels_list.json
|
83
86
|
- spec/support/fixtures/groups_info.json
|
84
87
|
- spec/support/fixtures/groups_list.json
|
88
|
+
- spec/support/fixtures/oauth_access.json
|
85
89
|
- spec/support/fixtures/successful_response.json
|
86
90
|
- spec/support/fixtures/users_info.json
|
87
91
|
- spec/support/fixtures/users_list.json
|
@@ -114,6 +118,7 @@ test_files:
|
|
114
118
|
- spec/laziness/api/auth_spec.rb
|
115
119
|
- spec/laziness/api/channels_spec.rb
|
116
120
|
- spec/laziness/api/groups_spec.rb
|
121
|
+
- spec/laziness/api/oauth_spec.rb
|
117
122
|
- spec/laziness/api/users_spec.rb
|
118
123
|
- spec/laziness/client_spec.rb
|
119
124
|
- spec/laziness/errors_spec.rb
|
@@ -123,6 +128,7 @@ test_files:
|
|
123
128
|
- spec/support/fixtures/channels_list.json
|
124
129
|
- spec/support/fixtures/groups_info.json
|
125
130
|
- spec/support/fixtures/groups_list.json
|
131
|
+
- spec/support/fixtures/oauth_access.json
|
126
132
|
- spec/support/fixtures/successful_response.json
|
127
133
|
- spec/support/fixtures/users_info.json
|
128
134
|
- spec/support/fixtures/users_list.json
|