laziness 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f0de21632ae16b077bc175fec281de93eb1ed6a5
4
- data.tar.gz: ac123e7b8d889a6e6d046dcd7fb901177d32157b
3
+ metadata.gz: 1c21fdd45b9b2235fd96fd6c2e6328d891740f61
4
+ data.tar.gz: d42ae47015490c1546cec9c039413a8bc0a6674a
5
5
  SHA512:
6
- metadata.gz: 6adc63b530bd9151372230a526a9a69a5ef8bfeebad95085142cb47a4c4dfecfb9453809cfef7c5c94dd94061284c0ec4ae2d1492d5ff549c5ad85e82a6e3eab
7
- data.tar.gz: 24148d3b129546de9909e8ca74060c43f36e5b3b64a798aa56d3fbd2cf4deeea1a86d00aa4d48aa52cbd0c27fb36fade143e5abe438dd55755c38dc8e07d12ed
6
+ metadata.gz: 8fd70990ed38c9fc9db9c41fad42a98b131b224e0c40eb758eb22843784973d54d568d43a1b4a46f6889e73542c359dd134e1e8f6f7c69e13145c7c671c90ac2
7
+ data.tar.gz: 8940eb5f16ba6feef11632fc0ee79e606b0896da432ec393ef12f7b08b37d10153cceb0c71ed4c6ce79fef75dc4cca84eb90d211c9450525706a88a89b519c88
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- laziness (0.1.3)
4
+ laziness (0.1.4)
5
5
  hashie
6
6
  httparty
7
7
 
data/README.md CHANGED
@@ -36,10 +36,10 @@ client = Slack.client(access_token: "your-access-token")
36
36
  ```
37
37
  client.channels.all # lists out all the channels
38
38
  client.channels.find(channel_id) # get info about a specific channel
39
- client.channels.archive!(channel_id) # archives the specific channel
39
+ client.channels.archive(channel_id) # archives the specific channel
40
+ client.channels.unarchive(channel_id) # unarchives the specific channel
40
41
 
41
- channel = Slack::Channel.new(name: "testing")
42
- client.channels.create(channel) # creates the new channel
42
+ channel = client.channels.create("testing") # creates the new channel
43
43
 
44
44
  client.channels.history(channel_id, latest: DateTime.now, oldest: 2.weeks.ago, count: 1000) # lists out the messages for the specific channels
45
45
  client.channels.invite(channel_id, user_id) # invites the specific user to the specific channel
@@ -65,11 +65,36 @@ client.channels.invite(channel_id, user_id) # invites the specific user to the s
65
65
 
66
66
  ### Groups
67
67
 
68
+ ```
69
+ client.groups.all # lists out all the groups
70
+ client.groups.find(group_id) # get info about a specific group
71
+ client.groups.archive(group_id) # archives the specific group
72
+ client.groups.close(group_id) # closes the specific group
73
+ client.groups.unarchive(group_id) # unarchives the specific group
74
+
75
+ group = client.groups.create("testing") # creates the new group
76
+ group = client.groups.copy(group_id) # archives the specified group and returns a copy
77
+ group = client.groups.invite(group_id, user_id) # invites the specified user to the specified group and returns the group
78
+ client.groups.kick(group_id, user_id) # removes the specified user from the specified group
79
+ client.groups.leave(group_id) # removes the current user from the specified group
80
+ client.groups.open(group_id) # opens the specified group
81
+ client.groups.update_purpose(group_id, purpose) # updates the purpose for the specific group
82
+ client.groups.update_topic(group_id, topic) # updates the topic for the specific group
83
+ ```
84
+
85
+ #### TODO:
86
+
87
+ - [ ] [groups.history](https://api.slack.com/methods/groups.history)
88
+ - [ ] [groups.mark](https://api.slack.com/methods/groups.mark)
89
+ - [ ] [groups.rename](https://api.slack.com/methods/groups.rename)
90
+
68
91
  ### IM
69
92
 
70
93
  ### Auth
71
94
 
95
+ ```
72
96
  client.auth.test # get info about a specific oauth token
97
+ ```
73
98
 
74
99
  ### Presence
75
100
 
@@ -13,9 +13,14 @@ module Slack
13
13
  "https://slack.com/api/"
14
14
  end
15
15
 
16
+ def with_nil_response
17
+ yield
18
+ nil
19
+ end
20
+
16
21
  def request(method, access_token, path, arguments={})
17
22
  full_path = "#{base_path}#{path}?token=#{access_token}"
18
- arguments.each_pair { |key, value| full_path = "#{full_path}&#{key}=#{value}" }
23
+ arguments.each_pair { |key, value| full_path = "#{full_path}&#{key}=#{ERB::Util.url_encode(value)}" }
19
24
  options = {
20
25
  headers: {
21
26
  "Accept" => "application/json",
@@ -6,9 +6,8 @@ module Slack
6
6
  Slack::Channel.parse response, 'channels'
7
7
  end
8
8
 
9
- def find(id)
10
- response = request :get, access_token, 'channels.info', channel: id
11
- Slack::Channel.parse response, 'channel'
9
+ def archive(id)
10
+ with_nil_response { request :post, access_token, 'channels.archive', channel: id }
12
11
  end
13
12
 
14
13
  def create(name)
@@ -16,14 +15,13 @@ module Slack
16
15
  Slack::Channel.parse response, 'channel'
17
16
  end
18
17
 
19
- def archive(id)
20
- request :post, access_token, 'channels.archive', channel: id
21
- nil
18
+ def find(id)
19
+ response = request :get, access_token, 'channels.info', channel: id
20
+ Slack::Channel.parse response, 'channel'
22
21
  end
23
22
 
24
23
  def unarchive(id)
25
- request :post, access_token, 'channels.unarchive', channel: id
26
- nil
24
+ with_nil_response { request :post, access_token, 'channels.unarchive', channel: id }
27
25
  end
28
26
  end
29
27
  end
@@ -0,0 +1,62 @@
1
+ module Slack
2
+ module API
3
+ class Groups < Base
4
+ def all(exclude_archived=false)
5
+ response = request :get, access_token, 'groups.list', exclude_archived: exclude_archived ? 1 : 0
6
+ Slack::Group.parse response, 'groups'
7
+ end
8
+
9
+ def archive(id)
10
+ with_nil_response { request :post, access_token, 'groups.archive', channel: id }
11
+ end
12
+
13
+ def close(id)
14
+ with_nil_response { request :post, access_token, 'groups.close', channel: id }
15
+ end
16
+
17
+ def copy(id)
18
+ response = request :post, access_token, 'groups.createChild', channel: id
19
+ Slack::Group.parse response, 'group'
20
+ end
21
+
22
+ def create(name)
23
+ response = request :post, access_token, 'groups.create', name: name
24
+ Slack::Group.parse response, 'group'
25
+ end
26
+
27
+ def find(id)
28
+ response = request :get, access_token, 'groups.info', channel: id
29
+ Slack::Group.parse response, 'group'
30
+ end
31
+
32
+ def invite(id, user_id)
33
+ response = request :post, access_token, 'groups.invite', channel: id, user: user_id
34
+ Slack::Group.parse response, 'group'
35
+ end
36
+
37
+ def kick(id, user_id)
38
+ with_nil_response { request :post, access_token, 'groups.kick', channel: id, user: user_id }
39
+ end
40
+
41
+ def leave(id)
42
+ with_nil_response { request :post, access_token, 'groups.leave', channel: id }
43
+ end
44
+
45
+ def open(id)
46
+ with_nil_response { request :post, access_token, 'groups.open', channel: id }
47
+ end
48
+
49
+ def unarchive(id)
50
+ with_nil_response { request :post, access_token, 'groups.unarchive', channel: id }
51
+ end
52
+
53
+ def update_purpose(id, purpose)
54
+ with_nil_response { request :post, access_token, 'groups.setPurpose', channel: id, purpose: purpose }
55
+ end
56
+
57
+ def update_topic(id, topic)
58
+ with_nil_response { request :post, access_token, 'groups.setTopic', channel: id, topic: topic }
59
+ end
60
+ end
61
+ end
62
+ end
@@ -12,8 +12,7 @@ module Slack
12
12
  end
13
13
 
14
14
  def set_active
15
- request :post, access_token, 'users.setActive'
16
- nil
15
+ with_nil_response { request :post, access_token, 'users.setActive' }
17
16
  end
18
17
  end
19
18
  end
data/lib/laziness/api.rb CHANGED
@@ -3,4 +3,5 @@ require 'httparty'
3
3
  require 'laziness/api/base'
4
4
  require 'laziness/api/auth'
5
5
  require 'laziness/api/channels'
6
+ require 'laziness/api/groups'
6
7
  require 'laziness/api/users'
@@ -10,12 +10,16 @@ module Slack
10
10
  @auth ||= Slack::API::Auth.new(access_token)
11
11
  end
12
12
 
13
- def users
14
- @users ||= Slack::API::Users.new(access_token)
15
- end
16
-
17
13
  def channels
18
14
  @channels ||= Slack::API::Channels.new(access_token)
19
15
  end
16
+
17
+ def groups
18
+ @groups ||= Slack::API::Groups.new(access_token)
19
+ end
20
+
21
+ def users
22
+ @users ||= Slack::API::Users.new(access_token)
23
+ end
20
24
  end
21
25
  end
@@ -0,0 +1,4 @@
1
+ module Slack
2
+ class Group < Base
3
+ end
4
+ end
@@ -1,3 +1,3 @@
1
1
  module Slack
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
data/lib/laziness.rb CHANGED
@@ -5,6 +5,7 @@ require 'laziness/auth'
5
5
  require 'laziness/channel'
6
6
  require 'laziness/client'
7
7
  require 'laziness/errors'
8
+ require 'laziness/group'
8
9
  require 'laziness/user'
9
10
 
10
11
  module Slack
@@ -12,13 +12,12 @@ describe Slack::API:: Channels do
12
12
  end
13
13
  end
14
14
 
15
- describe '.find' do
16
- it 'returns the specific channel with the specified id' do
17
- stub_slack_request :get, "channels.info?channel=C02BLAH&token=#{access_token}", 'channels_info.json'
15
+ describe '.archive' do
16
+ it 'marks the channel as archived' do
17
+ stub = stub_slack_request :post, "channels.archive?channel=C02BLAH&token=#{access_token}", 'successful_response.json'
18
18
 
19
- channel = subject.find("C02BLAH")
20
- expect(channel.id).to eq "C02BLAH"
21
- expect(channel.name).to eq "tour"
19
+ expect(subject.archive("C02BLAH")).to be_nil
20
+ expect(stub).to have_been_requested
22
21
  end
23
22
  end
24
23
 
@@ -32,12 +31,13 @@ describe Slack::API:: Channels do
32
31
  end
33
32
  end
34
33
 
35
- describe '.archive' do
36
- it 'marks the channel as archived' do
37
- stub = stub_slack_request :post, "channels.archive?channel=C02BLAH&token=#{access_token}", 'successful_response.json'
34
+ describe '.find' do
35
+ it 'returns the specific channel with the specified id' do
36
+ stub_slack_request :get, "channels.info?channel=C02BLAH&token=#{access_token}", 'channels_info.json'
38
37
 
39
- expect(subject.archive("C02BLAH")).to be_nil
40
- expect(stub).to have_been_requested
38
+ channel = subject.find("C02BLAH")
39
+ expect(channel.id).to eq "C02BLAH"
40
+ expect(channel.name).to eq "tour"
41
41
  end
42
42
  end
43
43
 
@@ -0,0 +1,126 @@
1
+ describe Slack::API::Groups do
2
+ let(:access_token) { "12345" }
3
+ subject { Slack::API::Groups.new access_token }
4
+
5
+ describe '.all' do
6
+ it 'returns all the groups for an account' do
7
+ stub_slack_request :get, "groups.list?exclude_archived=0&token=#{access_token}", 'groups_list.json'
8
+
9
+ groups = subject.all
10
+ expect(groups.length).to eq 1
11
+ expect(groups[0].id).to eq "G02BLAH"
12
+ end
13
+ end
14
+
15
+ describe '.archive' do
16
+ it 'marks the group as archived' do
17
+ stub = stub_slack_request :post, "groups.archive?channel=G02BLAH&token=#{access_token}", 'successful_response.json'
18
+
19
+ expect(subject.archive("G02BLAH")).to be_nil
20
+ expect(stub).to have_been_requested
21
+ end
22
+ end
23
+
24
+ describe '.close' do
25
+ it 'closes the group' do
26
+ stub = stub_slack_request :post, "groups.close?channel=G02BLAH&token=#{access_token}", 'successful_response.json'
27
+
28
+ expect(subject.close("G02BLAH")).to be_nil
29
+ expect(stub).to have_been_requested
30
+ end
31
+ end
32
+
33
+ describe '.copy' do
34
+ it 'creates a new group, archives the existing group, and returns the new group' do
35
+ stub_slack_request :post, "groups.createChild?channel=G02BLAH&token=#{access_token}", 'groups_info.json'
36
+
37
+ group = subject.copy("G02BLAH")
38
+ expect(group.id).to eq "G02BLAH"
39
+ expect(group.name).to eq "music"
40
+ end
41
+ end
42
+
43
+ describe '.create' do
44
+ it 'creates a new group and returns the specified group' do
45
+ stub_slack_request :post, "groups.create?name=music&token=#{access_token}", 'groups_info.json'
46
+
47
+ group = subject.create("music")
48
+ expect(group.id).to eq "G02BLAH"
49
+ expect(group.name).to eq "music"
50
+ end
51
+ end
52
+
53
+ describe '.find' do
54
+ it 'returns the specific group with the specified id' do
55
+ stub_slack_request :get, "groups.info?channel=G02BLAH&token=#{access_token}", 'groups_info.json'
56
+
57
+ group = subject.find("G02BLAH")
58
+ expect(group.id).to eq "G02BLAH"
59
+ expect(group.name).to eq "music"
60
+ end
61
+ end
62
+
63
+ describe '.invite' do
64
+ it 'returns the specific group with the specified id' do
65
+ stub_slack_request :post, "groups.invite?channel=G02BLAH&user=U024BLAH&token=#{access_token}", 'groups_info.json'
66
+
67
+ group = subject.invite("G02BLAH", "U024BLAH")
68
+ expect(group.id).to eq "G02BLAH"
69
+ expect(group.name).to eq "music"
70
+ end
71
+ end
72
+
73
+ describe '.kick' do
74
+ it 'removes the specified user from the specified group' do
75
+ stub = stub_slack_request :post, "groups.kick?channel=G02BLAH&user=U024BLAH&token=#{access_token}", 'successful_response.json'
76
+
77
+ expect(subject.kick("G02BLAH", "U024BLAH")).to be_nil
78
+ expect(stub).to have_been_requested
79
+ end
80
+ end
81
+
82
+ describe '.leave' do
83
+ it 'removes the current user from the specified group' do
84
+ stub = stub_slack_request :post, "groups.leave?channel=G02BLAH&token=#{access_token}", 'successful_response.json'
85
+
86
+ expect(subject.leave("G02BLAH")).to be_nil
87
+ expect(stub).to have_been_requested
88
+ end
89
+ end
90
+
91
+ describe '.open' do
92
+ it 'opens the group' do
93
+ stub = stub_slack_request :post, "groups.open?channel=G02BLAH&token=#{access_token}", 'successful_response.json'
94
+
95
+ expect(subject.open("G02BLAH")).to be_nil
96
+ expect(stub).to have_been_requested
97
+ end
98
+ end
99
+
100
+ describe '.unarchive' do
101
+ it 'marks the group as unarchived' do
102
+ stub = stub_slack_request :post, "groups.unarchive?channel=G02BLAH&token=#{access_token}", 'successful_response.json'
103
+
104
+ expect(subject.unarchive("G02BLAH")).to be_nil
105
+ expect(stub).to have_been_requested
106
+ end
107
+ end
108
+
109
+ describe '.update_purpose' do
110
+ it 'updates the groups purpose' do
111
+ stub = stub_slack_request :post, "groups.setPurpose?channel=G02BLAH&purpose=This%20is%20a%20new%20purpose&token=#{access_token}", 'successful_response.json'
112
+
113
+ expect(subject.update_purpose("G02BLAH", "This is a new purpose")).to be_nil
114
+ expect(stub).to have_been_requested
115
+ end
116
+ end
117
+
118
+ describe '.update_topic' do
119
+ it 'updates the groups topic' do
120
+ stub = stub_slack_request :post, "groups.setTopic?channel=G02BLAH&topic=This%20is%20a%20new%20topic&token=#{access_token}", 'successful_response.json'
121
+
122
+ expect(subject.update_topic("G02BLAH", "This is a new topic")).to be_nil
123
+ expect(stub).to have_been_requested
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,25 @@
1
+ {
2
+ "ok": true,
3
+ "group": {
4
+ "id": "G02BLAH",
5
+ "name": "music",
6
+ "is_group": true,
7
+ "created": 1403798029,
8
+ "creator": "U024BLAH",
9
+ "is_archived": false,
10
+ "members": [
11
+ "U024BLAH",
12
+ "U024BLAH2"
13
+ ],
14
+ "topic": {
15
+ "value": "",
16
+ "creator": "",
17
+ "last_set": 0
18
+ },
19
+ "purpose": {
20
+ "value": "A place to discuss musical influences",
21
+ "creator": "U024BLAH",
22
+ "last_set": 1403798029
23
+ }
24
+ }
25
+ }
@@ -0,0 +1,27 @@
1
+ {
2
+ "ok": true,
3
+ "groups": [
4
+ {
5
+ "id": "G02BLAH",
6
+ "name": "music",
7
+ "is_group": true,
8
+ "created": 1403798029,
9
+ "creator": "U024BLAH",
10
+ "is_archived": false,
11
+ "members": [
12
+ "U024BLAH",
13
+ "U024BLAH2"
14
+ ],
15
+ "topic": {
16
+ "value": "",
17
+ "creator": "",
18
+ "last_set": 0
19
+ },
20
+ "purpose": {
21
+ "value": "A place to discuss musical influences",
22
+ "creator": "U024BLAH",
23
+ "last_set": 1403798029
24
+ }
25
+ }
26
+ ]
27
+ }
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.3
4
+ version: 0.1.4
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-04-15 00:00:00.000000000 Z
11
+ date: 2015-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -60,16 +60,19 @@ files:
60
60
  - lib/laziness/api/auth.rb
61
61
  - lib/laziness/api/base.rb
62
62
  - lib/laziness/api/channels.rb
63
+ - lib/laziness/api/groups.rb
63
64
  - lib/laziness/api/users.rb
64
65
  - lib/laziness/auth.rb
65
66
  - lib/laziness/base.rb
66
67
  - lib/laziness/channel.rb
67
68
  - lib/laziness/client.rb
68
69
  - lib/laziness/errors.rb
70
+ - lib/laziness/group.rb
69
71
  - lib/laziness/user.rb
70
72
  - lib/laziness/version.rb
71
73
  - spec/laziness/api/auth_spec.rb
72
74
  - spec/laziness/api/channels_spec.rb
75
+ - spec/laziness/api/groups_spec.rb
73
76
  - spec/laziness/api/users_spec.rb
74
77
  - spec/laziness/client_spec.rb
75
78
  - spec/laziness/errors_spec.rb
@@ -77,6 +80,8 @@ files:
77
80
  - spec/support/fixtures/auth_test.json
78
81
  - spec/support/fixtures/channels_info.json
79
82
  - spec/support/fixtures/channels_list.json
83
+ - spec/support/fixtures/groups_info.json
84
+ - spec/support/fixtures/groups_list.json
80
85
  - spec/support/fixtures/successful_response.json
81
86
  - spec/support/fixtures/users_info.json
82
87
  - spec/support/fixtures/users_list.json
@@ -108,6 +113,7 @@ summary: A Slack API wrapper written in Ruby.
108
113
  test_files:
109
114
  - spec/laziness/api/auth_spec.rb
110
115
  - spec/laziness/api/channels_spec.rb
116
+ - spec/laziness/api/groups_spec.rb
111
117
  - spec/laziness/api/users_spec.rb
112
118
  - spec/laziness/client_spec.rb
113
119
  - spec/laziness/errors_spec.rb
@@ -115,6 +121,8 @@ test_files:
115
121
  - spec/support/fixtures/auth_test.json
116
122
  - spec/support/fixtures/channels_info.json
117
123
  - spec/support/fixtures/channels_list.json
124
+ - spec/support/fixtures/groups_info.json
125
+ - spec/support/fixtures/groups_list.json
118
126
  - spec/support/fixtures/successful_response.json
119
127
  - spec/support/fixtures/users_info.json
120
128
  - spec/support/fixtures/users_list.json