casica 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fb1eb66fdec0c578cdda8a170a0fed6a683f40b9
4
+ data.tar.gz: 2385f4f599eacce4d3665d85eb3fe0fb53ae707d
5
+ SHA512:
6
+ metadata.gz: ff2f41ffa97c398128ed54898152b2602a0d3706cb3918f38c1053bf0c0191377e6e14240f232bdd92c02f0dd28577949db4c7469030d454c39ff4169e3d5291
7
+ data.tar.gz: 3d2de92adaff85f092a6a260b6cf2acebb2aab39485c4b404e723e888445fc201f9b6abfed2d575e2f7696174c098e275d3152fc273f518d283932408ee3944b
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.14.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in casica.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Yuta Igarashi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,109 @@
1
+ # Casica
2
+
3
+ Casica API Ruby Wrapper
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'casica'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install casica
20
+
21
+ ## Usage
22
+
23
+ see also: [https://casica.io/api_doc](https://casica.io/api_doc)
24
+
25
+ ### Initialize
26
+
27
+ ```ruby
28
+ client = Casica::Client.new(token: "<access_token>")
29
+ ```
30
+
31
+ ### Project API
32
+
33
+ #### GET /api/projects
34
+
35
+ ```ruby
36
+ client.projects
37
+ ```
38
+
39
+ ### Story API
40
+
41
+ #### GET /api/projects/<project_id>/stories
42
+
43
+ ```ruby
44
+ client.stories(project_id: <project_id>)
45
+ ```
46
+
47
+ #### POST /api/projects/<project_id>/stories
48
+
49
+ ```ruby
50
+ client.create_story(project_id: <project_id>, attributes: { title: 'Story Title' })
51
+ ```
52
+
53
+ #### PATCH /api/projects/<project_id>/stories/<story_serial_num>
54
+
55
+ ```ruby
56
+ client.update_story(project_id: <project_id>, story_serial_num: <story_serial_num>, attributes: { title: 'Updated Story Title' })
57
+ ```
58
+
59
+ #### DELETE /api/projects/<project_id>/stories/<story_serial_num>
60
+
61
+ ```ruby
62
+ client.destroy_story(project_id: <project_id>, story_serial_num: <story_serial_num>)
63
+ ```
64
+
65
+ #### PATCH /api/projects/<project_id>/stories/statuses
66
+
67
+ ```ruby
68
+ client.update_story_status(project_id: <project_id>, from_status: 'merged', to_status: 'stg_deployed')
69
+ ```
70
+
71
+ ### Task API
72
+
73
+ #### GET /api/projects/<project_id>/stories/<story_serial_num>/tasks
74
+
75
+ ```ruby
76
+ client.tasks(project_id: <project_id>, story_serial_num: <story_serial_num>)
77
+ ```
78
+
79
+ #### POST /api/projects/<project_id>/stories/<story_serial_num>/tasks
80
+
81
+ ```ruby
82
+ client.create_task(project_id: <project_id>, story_serial_num: <story_serial_num>, attributes: { title: 'Task Title' })
83
+ ```
84
+
85
+ #### PATCH /api/projects/<project_id>/stories/<story_serial_num>/tasks/<task_serial_num>
86
+
87
+ ```ruby
88
+ client.update_task(project_id: <project_id>, story_serial_num: <story_serial_num>, task_serial_num: <task_serial_num>, attributes: { title: 'Updated Task Title' })
89
+ ```
90
+
91
+ #### DELETE /api/projects/<project_id>/stories/<story_serial_num>/tasks/<task_serial_num>
92
+
93
+ ```ruby
94
+ client.destroy_task(project_id: <project_id>, story_serial_num: <story_serial_num>, task_serial_num: <task_serial_num>)
95
+ ```
96
+
97
+ #### PATCH /api/projects/<project_id>/tasks/statuses
98
+
99
+ ```ruby
100
+ client.update_task_status(project_id: <project_id>, from_status: 'merged', to_status: 'stg_deployed')
101
+ ```
102
+
103
+ ## Contributing
104
+
105
+ 1. Fork it ( https://github.com/startup-technology/casica-ruby/fork )
106
+ 2. Create your feature branch (git checkout -b my-new-feature)
107
+ 3. Commit your changes (git commit -am 'Add some feature')
108
+ 4. Push to the branch (git push origin my-new-feature)
109
+ 5. Create a new Pull Request
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "casica"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "pry"
14
+ binding.pry
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'casica/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "casica"
8
+ spec.version = Casica::VERSION
9
+ spec.authors = ["Yuta Igarashi"]
10
+ spec.email = ["y.iga.thunder@gmail.com"]
11
+
12
+ spec.summary = %q{Casica API Ruby Wrapper}
13
+ spec.description = %q{Casica API Ruby Wrapper}
14
+ spec.homepage = "https://github.com/startup-technology/casica-ruby"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_runtime_dependency "faraday", "~> 0.9"
24
+ spec.add_runtime_dependency "faraday_middleware"
25
+ spec.add_development_dependency "bundler", "~> 1.14"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
+ spec.add_development_dependency "pry"
29
+ end
@@ -0,0 +1,11 @@
1
+ require "faraday"
2
+ require "faraday_middleware"
3
+
4
+ require "casica/version"
5
+ require "casica/client"
6
+ require "casica/request"
7
+ require "casica/response"
8
+ require "casica/error"
9
+
10
+ module Casica
11
+ end
@@ -0,0 +1,61 @@
1
+ module Casica
2
+ class Client
3
+ def initialize(token:)
4
+ @token = token
5
+ end
6
+
7
+ def projects
8
+ api(:get, '/projects', :get)
9
+ end
10
+
11
+ def stories(project_id:)
12
+ api(:get, "/projects/#{project_id}/stories")
13
+ end
14
+
15
+ def tasks(project_id:, story_serial_num:)
16
+ api(:get, "/projects/#{project_id}/stories/#{story_serial_num}/tasks")
17
+ end
18
+
19
+ def create_story(project_id:, attributes: {})
20
+ api(:post, "/projects/#{project_id}/stories", story: attributes)
21
+ end
22
+
23
+ def update_story(project_id:, story_serial_num:, attributes: {})
24
+ api(:patch, "/projects/#{project_id}/stories/#{story_serial_num}", story: attributes)
25
+ end
26
+
27
+ def destroy_story(project_id:, story_serial_num:)
28
+ api(:delete, "/projects/#{project_id}/stories/#{story_serial_num}")
29
+ end
30
+
31
+ def update_story_status(project_id:, from_status:, to_status:)
32
+ api(:patch, "/projects/#{project_id}/stories/statuses", from_status: from_status, to_status: to_status)
33
+ end
34
+
35
+ def create_task(project_id:, story_serial_num:, attributes: {})
36
+ api(:post, "/projects/#{project_id}/stories/#{story_serial_num}/tasks", task: attributes)
37
+ end
38
+
39
+ def update_task(project_id:, story_serial_num:, task_serial_num:, attributes: {})
40
+ api(:patch, "/projects/#{project_id}/stories/#{story_serial_num}/tasks/#{task_serial_num}", task: attributes)
41
+ end
42
+
43
+ def destroy_task(project_id:, story_serial_num:, task_serial_num:)
44
+ api(:delete, "/projects/#{project_id}/stories/#{story_serial_num}/tasks/#{task_serial_num}")
45
+ end
46
+
47
+ def update_task_status(project_id:, from_status:, to_status:)
48
+ api(:patch, "/projects/#{project_id}/tasks/statuses", from_status: from_status, to_status: to_status)
49
+ end
50
+
51
+ private
52
+
53
+ def api(method, path, *args)
54
+ Casica::Response.new(request.send(:request, method, path, *args)).response
55
+ end
56
+
57
+ def request
58
+ @request ||= Casica::Request.new(token: @token)
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,9 @@
1
+ module Casica
2
+ class Error
3
+ attr_accessor :response
4
+
5
+ def initialize(response)
6
+ @response = response
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,34 @@
1
+ module Casica
2
+ class Request
3
+ def initialize(token: token)
4
+ @token = token
5
+ end
6
+
7
+ def request(method, path, *args)
8
+ connection.send(method, full_url(path), args, headers)
9
+ end
10
+
11
+ def headers
12
+ {
13
+ 'Authorization' => "Bearer #{@token}",
14
+ 'ContentType' => 'application/json'
15
+ }
16
+ end
17
+
18
+ def full_url(path)
19
+ "#{base_url}#{path}"
20
+ end
21
+
22
+ def base_url
23
+ @base_url ||= ENV['CASICA_BASE_URL'] || 'https://casica.io/api'
24
+ end
25
+
26
+ def connection
27
+ @connection ||= Faraday.new do |config|
28
+ config.request :json
29
+ config.response :json
30
+ config.adapter Faraday.default_adapter
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,33 @@
1
+ module Casica
2
+ class Response
3
+ def initialize(faraday_response)
4
+ @faraday_response = faraday_response
5
+ end
6
+
7
+ def method_missing(method, *args, &block)
8
+ return @faraday_response.send(method, *args, &block) if @faraday_response.respond_to?(method)
9
+ super
10
+ end
11
+
12
+ def success?
13
+ case @faraday_response.status
14
+ when 200..299 then true
15
+ when 400..499 then false
16
+ when 500..599 then false
17
+ else false
18
+ end
19
+ end
20
+
21
+ def failure?
22
+ !success?
23
+ end
24
+
25
+ def response
26
+ if success?
27
+ @faraday_response.body || true
28
+ else
29
+ Casica::Error.new(self)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module Casica
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: casica
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yuta Igarashi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-08-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.9'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.14'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.14'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Casica API Ruby Wrapper
98
+ email:
99
+ - y.iga.thunder@gmail.com
100
+ executables:
101
+ - console
102
+ - setup
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - ".gitignore"
107
+ - ".rspec"
108
+ - ".travis.yml"
109
+ - Gemfile
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - bin/console
114
+ - bin/setup
115
+ - casica.gemspec
116
+ - lib/casica.rb
117
+ - lib/casica/client.rb
118
+ - lib/casica/error.rb
119
+ - lib/casica/request.rb
120
+ - lib/casica/response.rb
121
+ - lib/casica/version.rb
122
+ homepage: https://github.com/startup-technology/casica-ruby
123
+ licenses:
124
+ - MIT
125
+ metadata: {}
126
+ post_install_message:
127
+ rdoc_options: []
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ requirements: []
141
+ rubyforge_project:
142
+ rubygems_version: 2.6.11
143
+ signing_key:
144
+ specification_version: 4
145
+ summary: Casica API Ruby Wrapper
146
+ test_files: []