laziness 0.1.4 → 0.1.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1c21fdd45b9b2235fd96fd6c2e6328d891740f61
4
- data.tar.gz: d42ae47015490c1546cec9c039413a8bc0a6674a
3
+ metadata.gz: 622956ad7a455f78936d697f1f21cd6cb62c820c
4
+ data.tar.gz: c4f4653e0dd6667d43a3ff45f8eab4063b4a1690
5
5
  SHA512:
6
- metadata.gz: 8fd70990ed38c9fc9db9c41fad42a98b131b224e0c40eb758eb22843784973d54d568d43a1b4a46f6889e73542c359dd134e1e8f6f7c69e13145c7c671c90ac2
7
- data.tar.gz: 8940eb5f16ba6feef11632fc0ee79e606b0896da432ec393ef12f7b08b37d10153cceb0c71ed4c6ce79fef75dc4cca84eb90d211c9450525706a88a89b519c88
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)
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.1)
16
- httparty (0.13.3)
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.2)
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`
@@ -2,7 +2,7 @@ module Slack
2
2
  module API
3
3
  class Auth < Base
4
4
  def test
5
- response = request :get, access_token, 'auth.test'
5
+ response = request :get, 'auth.test'
6
6
  Slack::Auth.parse response
7
7
  end
8
8
  end
@@ -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, access_token, path, arguments={})
22
- full_path = "#{base_path}#{path}?token=#{access_token}"
23
- arguments.each_pair { |key, value| full_path = "#{full_path}&#{key}=#{ERB::Util.url_encode(value)}" }
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, access_token, 'channels.list', exclude_archived: exclude_archived ? 1 : 0
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, access_token, 'channels.archive', channel: id }
10
+ with_nil_response { request :post, 'channels.archive', channel: id }
11
11
  end
12
12
 
13
13
  def create(name)
14
- response = request :post, access_token, 'channels.create', name: name
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, access_token, 'channels.info', channel: id
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, access_token, 'channels.unarchive', channel: id }
24
+ with_nil_response { request :post, 'channels.unarchive', channel: id }
25
25
  end
26
26
  end
27
27
  end
@@ -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, access_token, 'groups.list', exclude_archived: exclude_archived ? 1 : 0
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, access_token, 'groups.archive', channel: id }
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, access_token, 'groups.close', channel: id }
14
+ with_nil_response { request :post, 'groups.close', channel: id }
15
15
  end
16
16
 
17
17
  def copy(id)
18
- response = request :post, access_token, 'groups.createChild', channel: id
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, access_token, 'groups.create', name: name
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, access_token, 'groups.info', channel: id
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, access_token, 'groups.invite', channel: id, user: user_id
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, access_token, 'groups.kick', channel: id, user: user_id }
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, access_token, 'groups.leave', channel: id }
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, access_token, 'groups.open', channel: id }
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, access_token, 'groups.unarchive', channel: id }
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, access_token, 'groups.setPurpose', channel: id, purpose: purpose }
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, access_token, 'groups.setTopic', channel: id, topic: topic }
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
@@ -2,17 +2,17 @@ module Slack
2
2
  module API
3
3
  class Users < Base
4
4
  def all
5
- response = request :get, access_token, 'users.list'
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, access_token, 'users.info', user: id
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, access_token, 'users.setActive' }
15
+ with_nil_response { request :post, 'users.setActive' }
16
16
  end
17
17
  end
18
18
  end
data/lib/laziness/api.rb CHANGED
@@ -4,4 +4,5 @@ require 'laziness/api/base'
4
4
  require 'laziness/api/auth'
5
5
  require 'laziness/api/channels'
6
6
  require 'laziness/api/groups'
7
+ require 'laziness/api/oauth'
7
8
  require 'laziness/api/users'
@@ -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
@@ -0,0 +1,4 @@
1
+ module Slack
2
+ class OAuth < Base
3
+ end
4
+ end
@@ -1,3 +1,3 @@
1
1
  module Slack
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
data/lib/laziness.rb CHANGED
@@ -6,6 +6,7 @@ require 'laziness/channel'
6
6
  require 'laziness/client'
7
7
  require 'laziness/errors'
8
8
  require 'laziness/group'
9
+ require 'laziness/oauth'
9
10
  require 'laziness/user'
10
11
 
11
12
  module Slack
@@ -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
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-06-16 00:00:00.000000000 Z
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