api_for_asana 0.0.2 → 0.0.3
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 +4 -4
- data/api_for_asana.gemspec +2 -0
- data/lib/api_for_asana/helper.rb +8 -0
- data/lib/api_for_asana/version.rb +1 -1
- data/lib/api_for_asana.rb +27 -47
- data/spec/api_for_asana_spec.rb +32 -81
- metadata +30 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7b3f292508c7d9a1e1c68a73afb5402518b9e1e45b199543102d5209dec48dd5
|
|
4
|
+
data.tar.gz: 8d1b2d3080291a30d04af55879bee1f61b4c4dc6ae660c942197f30b80cea8fb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b48c58ea6466aec0674cfca314bdb2f3b44055e10ed593a99839e36c9fa60e18ce64bd7fc0c0fe200775d3dfd372718ba780f2f30109200d816e0d7f787d3f67
|
|
7
|
+
data.tar.gz: 16c0358509964889cf39b742b7352280e85b342b32138be376624d0b2b0f968c2403ce16bd3d3c51302c8dfdc84b1f4df55250f67c54975e3f5f7262437d2fde
|
data/api_for_asana.gemspec
CHANGED
|
@@ -12,6 +12,8 @@ Gem::Specification.new do |spec|
|
|
|
12
12
|
spec.files = Dir['lib/**/*.rb', 'LICENSE', 'spec/**/*.rb', 'api_for_asana.gemspec', 'README.md', 'Gemfile']
|
|
13
13
|
spec.add_development_dependency 'rspec'
|
|
14
14
|
spec.add_development_dependency 'rspec-rails'
|
|
15
|
+
spec.add_development_dependency 'dotenv'
|
|
16
|
+
spec.add_development_dependency 'webmock'
|
|
15
17
|
|
|
16
18
|
|
|
17
19
|
# spec.metadata = {
|
data/lib/api_for_asana.rb
CHANGED
|
@@ -1,72 +1,52 @@
|
|
|
1
1
|
require 'net/http'
|
|
2
|
+
require 'dotenv'
|
|
3
|
+
require_relative './api_for_asana/helper'
|
|
4
|
+
|
|
2
5
|
module ApiForAsana
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
Net::HTTP.
|
|
8
|
-
|
|
9
|
-
end
|
|
6
|
+
include Helper
|
|
7
|
+
Dotenv.load
|
|
8
|
+
def get_section(project_id)
|
|
9
|
+
uri = URI("#{base_url}/projects/#{project_id}/sections")
|
|
10
|
+
req = Net::HTTP::Get.new(uri)
|
|
11
|
+
send_http_request(req, uri)
|
|
10
12
|
end
|
|
11
13
|
|
|
12
|
-
def get_tasks(
|
|
13
|
-
uri = URI("
|
|
14
|
+
def get_tasks(task_id)
|
|
15
|
+
uri = URI("#{base_url}/sections/#{task_id}/tasks")
|
|
14
16
|
req = Net::HTTP::Get.new(uri)
|
|
15
|
-
req
|
|
16
|
-
Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
|
|
17
|
-
http.request(req)
|
|
18
|
-
end
|
|
17
|
+
send_http_request(req, uri)
|
|
19
18
|
end
|
|
20
19
|
|
|
21
|
-
def update_section(
|
|
22
|
-
uri =
|
|
20
|
+
def update_section(section_id, name)
|
|
21
|
+
uri = URI("#{base_url}/sections/#{section_id}")
|
|
23
22
|
req = Net::HTTP::Put.new(uri)
|
|
24
|
-
req['Authorization'] = token
|
|
25
23
|
req.set_form_data(name: name)
|
|
26
|
-
|
|
27
|
-
http.request(req)
|
|
28
|
-
end
|
|
24
|
+
send_http_request(req, uri)
|
|
29
25
|
end
|
|
30
26
|
|
|
31
|
-
def create_section(name)
|
|
32
|
-
|
|
33
|
-
req
|
|
27
|
+
def create_section(project_id, name)
|
|
28
|
+
uri = URI("#{base_url}/projects/#{project_id}/sections")
|
|
29
|
+
req = Net::HTTP::Post.new(uri)
|
|
34
30
|
req.set_form_data(name: name)
|
|
35
|
-
|
|
36
|
-
http.request(req)
|
|
37
|
-
end
|
|
31
|
+
send_http_request(req, uri)
|
|
38
32
|
end
|
|
39
33
|
|
|
40
|
-
def delete_section(
|
|
41
|
-
uri =
|
|
34
|
+
def delete_section(section_id)
|
|
35
|
+
uri = URI("#{base_url}/sections/#{section_id}")
|
|
42
36
|
req = Net::HTTP::Delete.new(uri)
|
|
43
|
-
req
|
|
44
|
-
Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
|
|
45
|
-
http.request(req)
|
|
46
|
-
end
|
|
37
|
+
send_http_request(req, uri)
|
|
47
38
|
end
|
|
48
39
|
|
|
49
|
-
def update_task(
|
|
50
|
-
uri = URI("
|
|
40
|
+
def update_task(task_id, name)
|
|
41
|
+
uri = URI("#{base_url}/tasks/#{task_id}")
|
|
51
42
|
req = Net::HTTP::Put.new(uri)
|
|
52
|
-
req['Authorization'] = token
|
|
53
43
|
req.set_form_data(name: name)
|
|
54
|
-
|
|
55
|
-
http.request(req)
|
|
56
|
-
end
|
|
44
|
+
send_http_request(req, uri)
|
|
57
45
|
end
|
|
58
46
|
|
|
59
47
|
private
|
|
60
48
|
|
|
61
|
-
def
|
|
62
|
-
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def token
|
|
66
|
-
'Bearer 1/1204884589111623:bcd5f3b78ab8580dab44dda843374ad5'
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
def section_url(id)
|
|
70
|
-
URI("https://app.asana.com/api/1.0/sections/#{id}")
|
|
49
|
+
def base_url
|
|
50
|
+
'https://app.asana.com/api/1.0'
|
|
71
51
|
end
|
|
72
52
|
end
|
data/spec/api_for_asana_spec.rb
CHANGED
|
@@ -1,122 +1,73 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
3
|
require 'spec_helper'
|
|
6
|
-
|
|
4
|
+
require 'webmock/rspec'
|
|
7
5
|
require 'api_for_asana'
|
|
8
6
|
|
|
9
|
-
describe
|
|
10
|
-
|
|
11
|
-
let(:
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
describe ApiForAsana do
|
|
8
|
+
let(:base_url) { 'https://app.asana.com/api/1.0' }
|
|
9
|
+
let(:api) { Class.new { extend ApiForAsana } }
|
|
14
10
|
|
|
15
11
|
context 'When we try to access all section' do
|
|
16
|
-
|
|
17
12
|
it 'should return status code 200' do
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
stub_request(:get, "#{base_url}/projects/1204884610326667/sections")
|
|
14
|
+
.with(headers: { 'Authorization' => "Bearer #{ENV['API_KEY']}" })
|
|
15
|
+
res = api.get_section('1204884610326667')
|
|
21
16
|
expect(res.code).to eq('200')
|
|
22
|
-
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
context 'When we try to access a task list with wrong section id' do
|
|
30
|
-
|
|
31
|
-
it 'should return status code 404' do
|
|
32
|
-
|
|
33
|
-
res = dummy.get_tasks('45689')
|
|
34
|
-
|
|
35
|
-
expect(res.code).to eq('404')
|
|
36
|
-
|
|
37
17
|
end
|
|
38
|
-
|
|
39
18
|
end
|
|
40
19
|
|
|
41
|
-
context 'When we try to access a task list
|
|
42
|
-
|
|
20
|
+
context 'When we try to access a task list' do
|
|
43
21
|
it 'should return status code 200' do
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
22
|
+
stub_request(:get, "#{base_url}/sections/45689/tasks")
|
|
23
|
+
.with(headers: { 'Authorization' => "Bearer #{ENV['API_KEY']}" })
|
|
24
|
+
res = api.get_tasks('45689')
|
|
47
25
|
expect(res.code).to eq('200')
|
|
48
|
-
|
|
49
26
|
end
|
|
50
|
-
|
|
51
27
|
end
|
|
52
28
|
|
|
53
|
-
context 'When we try to update the section' do
|
|
54
29
|
|
|
55
|
-
it 'should return status code 200' do
|
|
56
|
-
|
|
57
|
-
res = dummy.update_section('1204884610326671', 'Completed')
|
|
58
30
|
|
|
31
|
+
context 'When we try to update the section' do
|
|
32
|
+
it 'should return status code 200' do
|
|
33
|
+
stub_request(:put, "#{base_url}/sections/1204884610326671")
|
|
34
|
+
.with(body: {name: 'Approved'}, headers: { 'Authorization' => "Bearer #{ENV['API_KEY']}" })
|
|
35
|
+
res = api.update_section('1204884610326671', 'Approved')
|
|
59
36
|
expect(res.code).to eq('200')
|
|
60
|
-
|
|
61
37
|
end
|
|
62
|
-
|
|
63
38
|
end
|
|
64
39
|
|
|
65
|
-
context 'When we try to update the section with wrong id' do
|
|
66
|
-
|
|
67
|
-
it 'should return status code 404' do
|
|
68
|
-
|
|
69
|
-
res = dummy.update_section('12048846103271', 'Completed')
|
|
70
|
-
|
|
71
|
-
expect(res.code).to eq('404')
|
|
72
|
-
|
|
73
|
-
end
|
|
74
40
|
|
|
75
|
-
|
|
76
|
-
context 'When we try to update the task
|
|
77
|
-
it 'should return status code 404' do
|
|
78
|
-
res = dummy.update_task('12048846103271', 'Draft Logo')
|
|
79
|
-
expect(res.code).to eq('404')
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
context 'When we try to update the task with valid task id' do
|
|
41
|
+
|
|
42
|
+
context 'When we try to update the task' do
|
|
83
43
|
it 'should return status code 200' do
|
|
84
|
-
|
|
44
|
+
stub_request(:put, "#{base_url}/tasks/12048846103271")
|
|
45
|
+
.with(body: {name: 'Draft Logo'}, headers: { 'Authorization' => "Bearer #{ENV['API_KEY']}" })
|
|
46
|
+
res = api.update_task('12048846103271', 'Draft Logo')
|
|
85
47
|
expect(res.code).to eq('200')
|
|
86
48
|
end
|
|
87
49
|
end
|
|
88
50
|
|
|
89
|
-
context 'When we try to create new section' do
|
|
90
51
|
|
|
91
|
-
it 'should return status code 201' do
|
|
92
|
-
|
|
93
|
-
res = dummy.create_section('Approved')
|
|
94
52
|
|
|
53
|
+
context 'When we try to create new section' do
|
|
54
|
+
it 'should return status code 201' do
|
|
55
|
+
stub_request(:post, "#{base_url}/projects/1204884610326667/sections")
|
|
56
|
+
.with(body: {name: 'Approved'}, headers: { 'Authorization' => "Bearer #{ENV['API_KEY']}" }).to_return( body: "", status: 201, headers: {})
|
|
57
|
+
res = api.create_section('1204884610326667', 'Approved')
|
|
95
58
|
expect(res.code).to eq('201')
|
|
96
|
-
|
|
97
59
|
end
|
|
98
|
-
|
|
99
60
|
end
|
|
100
61
|
|
|
101
|
-
context 'When we try to delete
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
res =
|
|
106
|
-
|
|
107
|
-
expect(res.code).to eq('404')
|
|
62
|
+
context 'When we try to delete section' do
|
|
63
|
+
it 'should return status code 200' do
|
|
64
|
+
stub_request(:delete, "#{base_url}/sections/12048846103271")
|
|
65
|
+
.with(headers: { 'Authorization' => "Bearer #{ENV['API_KEY']}" })
|
|
66
|
+
res = api.delete_section('12048846103271')
|
|
67
|
+
expect(res.code).to eq('200')
|
|
108
68
|
|
|
109
69
|
end
|
|
110
70
|
|
|
111
71
|
end
|
|
112
|
-
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
class Dummy
|
|
118
|
-
|
|
119
|
-
include ApiForAsana
|
|
120
|
-
|
|
121
72
|
end
|
|
122
73
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: api_for_asana
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Melashu Amare
|
|
@@ -38,6 +38,34 @@ dependencies:
|
|
|
38
38
|
- - ">="
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
40
|
version: '0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: dotenv
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: webmock
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
41
69
|
description:
|
|
42
70
|
email: meshu.amare@gmail.com
|
|
43
71
|
executables: []
|
|
@@ -48,6 +76,7 @@ files:
|
|
|
48
76
|
- README.md
|
|
49
77
|
- api_for_asana.gemspec
|
|
50
78
|
- lib/api_for_asana.rb
|
|
79
|
+
- lib/api_for_asana/helper.rb
|
|
51
80
|
- lib/api_for_asana/version.rb
|
|
52
81
|
- spec/api_for_asana_spec.rb
|
|
53
82
|
- spec/spec_helper.rb
|