api_for_asana 0.0.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c61fe2a69b0eaf817c822dff10feba5aacae6bf1cda4ebdc1d77892dfb3de758
4
- data.tar.gz: 71c09a33604ea30b71c23a762dcd05b08898524434c3ca631606e1cda11c2e91
3
+ metadata.gz: 7b3f292508c7d9a1e1c68a73afb5402518b9e1e45b199543102d5209dec48dd5
4
+ data.tar.gz: 8d1b2d3080291a30d04af55879bee1f61b4c4dc6ae660c942197f30b80cea8fb
5
5
  SHA512:
6
- metadata.gz: cdf6598b99a950097023d3bdb577dd45a6282fa810da752c48a6c341c363c594634e8b692bb73baee7702d2916d40677b5161ad51c314ec6f5981906518dd164
7
- data.tar.gz: 6b0c012def862bb1e26cabb7344c05881451f8b14e36ca2518e018dce35a5ba3447c0bbe69193a5060ea28c6c91848b68beb70c10ff5951f7daeb02f4a018a16
6
+ metadata.gz: b48c58ea6466aec0674cfca314bdb2f3b44055e10ed593a99839e36c9fa60e18ce64bd7fc0c0fe200775d3dfd372718ba780f2f30109200d816e0d7f787d3f67
7
+ data.tar.gz: 16c0358509964889cf39b742b7352280e85b342b32138be376624d0b2b0f968c2403ce16bd3d3c51302c8dfdc84b1f4df55250f67c54975e3f5f7262437d2fde
data/README.md ADDED
@@ -0,0 +1,107 @@
1
+
2
+ <a name="readme-top"></a>
3
+
4
+ # 📗 Table of Contents
5
+ - [📗 Table of Contents](#-table-of-contents)
6
+ - [📖 api\_for\_asana ](#-api_for_asana-)
7
+ - [Installation ](#installation-)
8
+ - [Usage](#usage)
9
+ - [To get all section](#to-get-all-section)
10
+ - [To update the section](#to-update-the-section)
11
+ - [To delete the section](#to-delete-the-section)
12
+ - [To create new section](#to-create-new-section)
13
+ - [Run Test](#run-test)
14
+ - [👥 Authors ](#-authors-)
15
+ - [🤝 Contributing ](#-contributing-)
16
+ - [⭐️ Show your support ](#️-show-your-support-)
17
+
18
+ # 📖 api_for_asana <a name="about-project"></a>
19
+
20
+ This gem is an API wrapper for interacting with Asana. It allows me to create sections, retrieve tasks from a given section, update sections, and delete sections.
21
+
22
+ ## Installation <a name="tech-stack"></a>
23
+
24
+ Add the following code to you Gemfile
25
+
26
+ ```ruby
27
+ gem 'api_for_asana'
28
+ ```
29
+
30
+ Then run
31
+
32
+ `bundler install`
33
+
34
+
35
+ ### Usage
36
+
37
+ `include` this gem on your controller like.
38
+
39
+ ```ruby
40
+ class HomesController < ApplicationController
41
+ include ApiForAsana
42
+
43
+ ...
44
+
45
+ end
46
+
47
+ ```
48
+
49
+
50
+
51
+
52
+ #### To get all section
53
+
54
+ Use get_sections method like below
55
+
56
+ ```ruby
57
+ get_sections
58
+
59
+ ```
60
+ #### To update the section
61
+
62
+ Use update_section method like below
63
+
64
+ ```ruby
65
+ update_section(id, name)
66
+
67
+ ```
68
+ #### To delete the section
69
+
70
+ Use delete_section method like below
71
+
72
+ ```ruby
73
+ delete_section(id)
74
+
75
+ ```
76
+
77
+ #### To create new section
78
+
79
+ Use create_section method like below
80
+
81
+ ```ruby
82
+ create_section(name)
83
+
84
+ ```
85
+ ### Run Test
86
+ on your terminal run
87
+ `rspec spec`
88
+
89
+ ## 👥 Authors <a name="authors"></a>
90
+
91
+ 👤 Melashu Amare
92
+
93
+ - GitHub: [@melashu](https://github.com/melashu)
94
+ - Twitter: [@meshu102](https://twitter.com/meshu102)
95
+ - LinkedIn: [Melashu Amare](https://www.linkedin.com/in/melashu-amare/)
96
+
97
+ ## 🤝 Contributing <a name="contributing"></a>
98
+
99
+ This repo is open for contributions. Issues, and feature requests are welcome!
100
+
101
+ Feel free to check the [issues page.](https://github.com/melashu/api_for_asana/issues)
102
+
103
+ ## ⭐️ Show your support <a name="support"></a>
104
+
105
+ Give a star if you like this project!
106
+
107
+ <p align="right">(<a href="#readme-top">back to top</a>)</p>
@@ -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 = {
@@ -0,0 +1,8 @@
1
+ module Helper
2
+ def send_http_request(req, uri)
3
+ req['Authorization'] = "Bearer #{ENV['API_KEY']}"
4
+ Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
5
+ http.request(req)
6
+ end
7
+ end
8
+ end
@@ -1,3 +1,3 @@
1
1
  module Version
2
- VERSION = "0.0.1"
2
+ VERSION = '0.0.3'
3
3
  end
data/lib/api_for_asana.rb CHANGED
@@ -1,62 +1,52 @@
1
1
  require 'net/http'
2
+ require 'dotenv'
3
+ require_relative './api_for_asana/helper'
4
+
2
5
  module ApiForAsana
3
-
4
- def get_sections
5
- req = Net::HTTP::Get.new(project_url)
6
- req['Authorization'] = token
7
- Net::HTTP.start(project_url.hostname, project_url.port, use_ssl: true) do |http|
8
- http.request(req)
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(id)
13
- uri = URI("https://app.asana.com/api/1.0/sections/#{id}/tasks")
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['Authorization'] = token
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(id, name)
22
- uri = section_url(id)
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
- Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
27
- http.request(req)
28
- end
24
+ send_http_request(req, uri)
29
25
  end
30
26
 
31
- def create_section(name)
32
- req = Net::HTTP::Post.new(project_url)
33
- req['Authorization'] = token
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
- Net::HTTP.start(project_url.hostname, project_url.port, use_ssl: true) do |http|
36
- http.request(req)
37
- end
31
+ send_http_request(req, uri)
38
32
  end
39
33
 
40
- def delete_section(id)
41
- uri = section_url(id)
34
+ def delete_section(section_id)
35
+ uri = URI("#{base_url}/sections/#{section_id}")
42
36
  req = Net::HTTP::Delete.new(uri)
43
- req['Authorization'] = token
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
- private
50
-
51
- def project_url
52
- URI('https://app.asana.com/api/1.0/projects/1204884610326667/sections')
40
+ def update_task(task_id, name)
41
+ uri = URI("#{base_url}/tasks/#{task_id}")
42
+ req = Net::HTTP::Put.new(uri)
43
+ req.set_form_data(name: name)
44
+ send_http_request(req, uri)
53
45
  end
54
46
 
55
- def token
56
- 'Bearer 1/1204884589111623:bcd5f3b78ab8580dab44dda843374ad5'
57
- end
47
+ private
58
48
 
59
- def section_url(id)
60
- URI("https://app.asana.com/api/1.0/sections/#{id}")
49
+ def base_url
50
+ 'https://app.asana.com/api/1.0'
61
51
  end
62
52
  end
@@ -1,110 +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 'ApiForAsana' do
10
-
11
- let(:dummy) { Dummy.new }
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
- res = dummy.get_sections
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
17
  end
24
-
25
18
  end
26
19
 
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
-
20
+ context 'When we try to access a task list' do
21
+ it 'should return status code 200' do
22
+ stub_request(:get, "#{base_url}/sections/45689/tasks")
23
+ .with(headers: { 'Authorization' => "Bearer #{ENV['API_KEY']}" })
24
+ res = api.get_tasks('45689')
25
+ expect(res.code).to eq('200')
37
26
  end
38
-
39
27
  end
40
28
 
41
- context 'When we try to access a task list with correct section id' do
42
29
 
43
- it 'should return status code 200' do
44
-
45
- res = dummy.get_tasks('1204884610326670')
46
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')
47
36
  expect(res.code).to eq('200')
48
-
49
37
  end
50
-
51
38
  end
52
39
 
53
- context 'When we try to update the section' do
54
40
 
41
+
42
+ context 'When we try to update the task' do
55
43
  it 'should return status code 200' do
56
-
57
- res = dummy.update_section('1204884610326671', 'Completed')
58
-
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')
59
47
  expect(res.code).to eq('200')
60
-
61
48
  end
62
-
63
49
  end
64
50
 
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
51
 
73
- end
74
-
75
- end
76
52
 
77
53
  context 'When we try to create new section' do
78
-
79
54
  it 'should return status code 201' do
80
-
81
- res = dummy.create_section('Approved')
82
-
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')
83
58
  expect(res.code).to eq('201')
84
-
85
59
  end
86
-
87
60
  end
88
61
 
89
- context 'When we try to delete non empty section' do
90
-
91
- it 'should return status code 404' do
92
-
93
- res = dummy.delete_section('12048846103271')
94
-
95
- 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')
96
68
 
97
69
  end
98
70
 
99
71
  end
100
-
101
- end
102
-
103
-
104
-
105
- class Dummy
106
-
107
- include ApiForAsana
108
-
109
72
  end
110
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.1
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: []
@@ -45,8 +73,10 @@ extensions: []
45
73
  extra_rdoc_files: []
46
74
  files:
47
75
  - Gemfile
76
+ - README.md
48
77
  - api_for_asana.gemspec
49
78
  - lib/api_for_asana.rb
79
+ - lib/api_for_asana/helper.rb
50
80
  - lib/api_for_asana/version.rb
51
81
  - spec/api_for_asana_spec.rb
52
82
  - spec/spec_helper.rb