chatwork 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.env.example +4 -0
- data/.gitignore +1 -0
- data/.gitmodules +3 -0
- data/.rubocop.yml +10 -0
- data/.travis.yml +26 -0
- data/.yardopts +2 -0
- data/CHANGELOG.md +33 -1
- data/Gemfile +13 -1
- data/README.md +15 -2
- data/Rakefile +2 -2
- data/bin/console +10 -0
- data/chatwork.gemspec +20 -9
- data/lib/chatwork.rb +32 -36
- data/lib/chatwork/base_client.rb +8 -11
- data/lib/chatwork/chatwork_error.rb +6 -16
- data/lib/chatwork/client.rb +2 -2
- data/lib/chatwork/contacts.rb +24 -8
- data/lib/chatwork/entity_methods.rb +36 -0
- data/lib/chatwork/file.rb +63 -0
- data/lib/chatwork/incoming_request.rb +71 -0
- data/lib/chatwork/me.rb +33 -8
- data/lib/chatwork/member.rb +55 -4
- data/lib/chatwork/message.rb +147 -6
- data/lib/chatwork/my_status.rb +25 -0
- data/lib/chatwork/my_task.rb +36 -8
- data/lib/chatwork/oauth_client.rb +3 -3
- data/lib/chatwork/room.rb +119 -6
- data/lib/chatwork/task.rb +96 -4
- data/lib/chatwork/token.rb +2 -2
- data/lib/chatwork/version.rb +1 -1
- data/spec/lib/chatwork/chatwork_error_spec.rb +10 -8
- data/spec/lib/chatwork/client_spec.rb +14 -14
- data/spec/lib/chatwork/contacts_spec.rb +11 -0
- data/spec/lib/chatwork/entity_methods_spec.rb +21 -0
- data/spec/lib/chatwork/file_spec.rb +37 -0
- data/spec/lib/chatwork/incoming_request_spec.rb +35 -0
- data/spec/lib/chatwork/me_spec.rb +39 -0
- data/spec/lib/chatwork/member_spec.rb +40 -9
- data/spec/lib/chatwork/message_spec.rb +102 -0
- data/spec/lib/chatwork/my_status_spec.rb +13 -0
- data/spec/lib/chatwork/my_task_spec.rb +19 -0
- data/spec/lib/chatwork/oauth_client_spec.rb +7 -7
- data/spec/lib/chatwork/room_spec.rb +102 -0
- data/spec/lib/chatwork/task_spec.rb +77 -0
- data/spec/lib/chatwork/token_spec.rb +26 -7
- data/spec/lib/chatwork_spec.rb +26 -19
- data/spec/lib/support/utils/raml_parser_spec.rb +96 -0
- data/spec/spec_helper.rb +32 -6
- data/spec/support/contexts/api_context.rb +43 -0
- data/spec/support/examples/a_chatwork_api.rb +12 -0
- data/spec/support/matchers/match_example.rb +16 -0
- data/spec/support/utils/raml_parser.rb +86 -0
- metadata +214 -10
- data/lib/chatwork/entity.rb +0 -29
- data/lib/chatwork/operations.rb +0 -48
- data/spec/shared_oauth_stubs.rb +0 -49
- data/spec/shared_stubs.rb +0 -39
data/lib/chatwork/entity.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
module ChatWork
|
2
|
-
class Entity
|
3
|
-
class << self
|
4
|
-
include Operations
|
5
|
-
def convert(hash)
|
6
|
-
# not implement
|
7
|
-
#converter = ResponseConverter.new
|
8
|
-
#converter.convert(hash)
|
9
|
-
return hash
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
attr_reader :attributes
|
14
|
-
|
15
|
-
def initialize(attributes)
|
16
|
-
@attributes = attributes
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
# not implement
|
22
|
-
def update_attributes(attributes)
|
23
|
-
raise "unexpected object" if attributes['object'] != @attributes['object']
|
24
|
-
new_object = ResponseConverter.new.convert(attributes)
|
25
|
-
@attributes = new_object.attributes
|
26
|
-
self
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
data/lib/chatwork/operations.rb
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
module ChatWork
|
2
|
-
module Operations
|
3
|
-
ACCEPT_PARAMS_ID = %i(file_id task_id message_id)
|
4
|
-
|
5
|
-
attr_accessor :assign_path
|
6
|
-
|
7
|
-
def install_class_operations(*operations)
|
8
|
-
define_create if operations.include?(:create)
|
9
|
-
define_get if operations.include?(:get)
|
10
|
-
end
|
11
|
-
|
12
|
-
def define_get
|
13
|
-
instance_eval do
|
14
|
-
def get(params = {}, &block)
|
15
|
-
@assign_path = parse_if_hash_key_exists(path, params, :room_id)
|
16
|
-
attach_nested_resource_id(params)
|
17
|
-
convert(ChatWork.client.get(@assign_path, params, &block))
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def define_create
|
23
|
-
instance_eval do
|
24
|
-
def create(params = {}, &block)
|
25
|
-
@assign_path = parse_if_hash_key_exists(path, params, :room_id)
|
26
|
-
attach_nested_resource_id(params)
|
27
|
-
convert(ChatWork.client.post(@assign_path, params, &block))
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
private
|
33
|
-
def parse_if_hash_key_exists(string, hash, key)
|
34
|
-
if hash.include?(key)
|
35
|
-
string % hash.delete(key)
|
36
|
-
else
|
37
|
-
string
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def attach_nested_resource_id(params)
|
42
|
-
ACCEPT_PARAMS_ID.each do |id_name|
|
43
|
-
next unless params.include? id_name
|
44
|
-
@assign_path += "/#{params.delete(id_name)}"
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
data/spec/shared_oauth_stubs.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'faraday'
|
2
|
-
|
3
|
-
RSpec.shared_context "shared oauth stubs" do
|
4
|
-
let(:client_id) { 'client_id' }
|
5
|
-
let(:client_secret) { 'client_secret' }
|
6
|
-
let(:refresh_token) { 'refresh_token' }
|
7
|
-
let(:api_version) { ChatWork.api_version }
|
8
|
-
let(:oauth_api_base) { ChatWork.oauth_api_base }
|
9
|
-
let(:signature) { 'Y2xpZW50X2lkOmNsaWVudF9zZWNyZXQ=' }
|
10
|
-
|
11
|
-
let(:test_adapter) {
|
12
|
-
token = {
|
13
|
-
access_token: 'new_access_token',
|
14
|
-
token_type: 'Bearer',
|
15
|
-
expires_in: '1800',
|
16
|
-
refresh_token: refresh_token,
|
17
|
-
scope: 'users.all:read rooms.all:read_write contacts.all:read_write'
|
18
|
-
}
|
19
|
-
|
20
|
-
Faraday::Adapter::Test::Stubs.new do |stub|
|
21
|
-
stub.post("/token") {
|
22
|
-
[200,
|
23
|
-
{"Content-Type" => "application/json"},
|
24
|
-
token.to_json ]
|
25
|
-
}
|
26
|
-
end
|
27
|
-
}
|
28
|
-
|
29
|
-
let(:faraday) {
|
30
|
-
default_header = {
|
31
|
-
'Authorization': "Basic #{signature}",
|
32
|
-
'User-Agent': "ChatWork#{api_version} RubyBinding/#{ChatWork::VERSION}"
|
33
|
-
}
|
34
|
-
Faraday.new(oauth_api_base, headers: default_header) do |builder|
|
35
|
-
builder.request :url_encoded
|
36
|
-
builder.adapter Faraday.default_adapter
|
37
|
-
builder.adapter :test, test_adapter
|
38
|
-
end
|
39
|
-
}
|
40
|
-
|
41
|
-
let(:oauth_client) {
|
42
|
-
allow(Faraday).to receive(:new).and_return(faraday)
|
43
|
-
ChatWork::OAuthClient.new(client_id, client_secret, oauth_api_base)
|
44
|
-
}
|
45
|
-
|
46
|
-
before(:each) do
|
47
|
-
allow(ChatWork).to receive(:oauth_client).and_return(oauth_client)
|
48
|
-
end
|
49
|
-
end
|
data/spec/shared_stubs.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'faraday'
|
2
|
-
|
3
|
-
RSpec.shared_context "shared stubs" do
|
4
|
-
let(:api_key) { 'api_key' }
|
5
|
-
let(:access_token) { nil }
|
6
|
-
let(:api_version) { ChatWork.api_version }
|
7
|
-
let(:api_base) { ChatWork.api_base }
|
8
|
-
|
9
|
-
let(:test_adapter) {
|
10
|
-
Faraday::Adapter::Test::Stubs.new do |stub|
|
11
|
-
stub.get("#{api_version}/rooms/1/members") { [200,
|
12
|
-
{'X-RateLimit-Limit': '100', 'X-RateLimit-Remaining': '44'},
|
13
|
-
[{ "account_id"=> 123, "name"=> "John Smith"}].to_json ]
|
14
|
-
}
|
15
|
-
end
|
16
|
-
}
|
17
|
-
|
18
|
-
let(:faraday) {
|
19
|
-
default_header = {
|
20
|
-
'X-ChatWorkToken': api_key,
|
21
|
-
'User-Agent': "ChatWork#{api_version} RubyBinding/#{ChatWork::VERSION}"
|
22
|
-
}
|
23
|
-
Faraday.new("#{api_base}#{api_version}", headers: default_header) do |builder|
|
24
|
-
builder.request :url_encoded
|
25
|
-
builder.adapter Faraday.default_adapter
|
26
|
-
builder.adapter :test, test_adapter
|
27
|
-
end
|
28
|
-
}
|
29
|
-
|
30
|
-
let(:client) {
|
31
|
-
allow(Faraday).to receive(:new).and_return(faraday)
|
32
|
-
client = ChatWork::Client.new(api_key, access_token, api_base, api_version)
|
33
|
-
client
|
34
|
-
}
|
35
|
-
|
36
|
-
before(:each) do
|
37
|
-
allow(ChatWork).to receive(:client).and_return(client)
|
38
|
-
end
|
39
|
-
end
|