esa 0.0.1 → 0.0.2

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: c7d9b5d5c382feb73b6bf8a6714ec15816f74e7f
4
- data.tar.gz: b3c920162debb1f6941ff0c1f8fec30493f72d96
3
+ metadata.gz: bedc15159efe6b571a0df4753902fe487ff8d8e1
4
+ data.tar.gz: 1188815dc7d971b4819c9fc9f396c12d71f5f913
5
5
  SHA512:
6
- metadata.gz: 173798517bd60ee374cb07ff14b03a3be83b9df9a70f97f603343e12d881d8b1afe17b591452235fcec527adf8f4b8fb896a69d5140cc45ebe506ed0f789eac2
7
- data.tar.gz: 8ea9093782efbdd0c3242d7638558d3fd8631c0c29dfe3eb6eeedacec369c84dd2c6963cc2b9041b31faab279c7840927b284b4eb26a7156a692cb567f83ec64
6
+ metadata.gz: 31aa9d801d5c975caee64580564b57dee14d6c72a1be07772f03abb627cccef2ba1d12227adb3f5cea5aae1adec3fa24e25b26b62e6696f0b3583e72f9a081bb
7
+ data.tar.gz: 96d3cc780482de6b84f4df04c7870b7f593d21546aaa2a0461690c0773894141326cbc7128e4d5d9cd82ac8249c0f02fb80d0c3f91988543d74d0197916babc5
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --require spec_helper
3
+ --format=progress --format=Nc
@@ -0,0 +1,17 @@
1
+ # More info at https://github.com/guard/guard#readme
2
+ guard :rspec, cmd: "bundle exec rspec" do
3
+ require "guard/rspec/dsl"
4
+ dsl = Guard::RSpec::Dsl.new(self)
5
+
6
+ # RSpec files
7
+ rspec = dsl.rspec
8
+ watch(rspec.spec_helper) { rspec.spec_dir }
9
+ watch(rspec.spec_support) { rspec.spec_dir }
10
+ watch(rspec.spec_files)
11
+
12
+ # Ruby files
13
+ ruby = dsl.ruby
14
+ dsl.watch_spec_files_for(ruby.lib_files)
15
+
16
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
17
+ end
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # Esa
1
+ # esa-ruby
2
2
 
3
- ( ⁰⊖⁰): Write a gem description
3
+ [WIP] esa API v2 client library, written in Ruby
4
4
 
5
5
  ## Installation
6
6
 
@@ -20,11 +20,31 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- ( ⁰⊖⁰): Write usage instructions here
23
+ ```ruby
24
+ client = Esa::Client.new(access_token: "<access_token>", current_team: 'foo')
25
+ client.teams
26
+ #=> GET /v1/teams
27
+
28
+ client.team('bar')
29
+ #=> GET /v1/teams/bar
30
+
31
+ client.posts
32
+ #=> GET /v1/teams/foo/posts
33
+
34
+ client.current_team = 'foobar'
35
+ client.post(1)
36
+ #=> GET /v1/teams/foobar/posts/1
37
+
38
+ client.update_post(1, name: 'baz')
39
+ #=> PATCH /v1/teams/foobar/posts/1
40
+
41
+ client.delete_post(1)
42
+ #=> DELETE /v1/teams/foobar/posts/1
43
+ ```
24
44
 
25
45
  ## Contributing
26
46
 
27
- 1. Fork it ( https://github.com/[my-github-username]/esa/fork )
47
+ 1. Fork it ( https://github.com/esaio/esa-ruby/fork )
28
48
  2. Create your feature branch (`git checkout -b my-new-feature`)
29
49
  3. Commit your changes (`git commit -am 'Add some feature'`)
30
50
  4. Push to the branch (`git push origin my-new-feature`)
data/Rakefile CHANGED
@@ -1,2 +1,5 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
2
3
 
4
+ RSpec::Core::RakeTask.new("spec")
5
+ task default: :spec
@@ -8,9 +8,9 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Esa::VERSION
9
9
  spec.authors = ["fukayatsu"]
10
10
  spec.email = ["fukayatsu@gmail.com"]
11
- spec.summary = %q{( ⁰⊖⁰): Write a short summary. Required.}
12
- spec.description = %q{( ⁰⊖⁰): Write a longer description. Optional.}
13
- spec.homepage = ""
11
+ spec.summary = %q{[WIP] esa API v2 client library, written in Ruby}
12
+ spec.description = %q{([WIP] esa API v2 client library, written in Ruby}
13
+ spec.homepage = "https://github.com/esaio/esa-ruby/"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
@@ -18,6 +18,15 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
+ spec.add_runtime_dependency "faraday", "~> 0.9"
22
+ spec.add_runtime_dependency "faraday_middleware"
21
23
  spec.add_development_dependency "bundler", "~> 1.7"
22
24
  spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "pry"
26
+ spec.add_development_dependency "rspec"
27
+ spec.add_development_dependency "webmock"
28
+ spec.add_development_dependency "vcr"
29
+ spec.add_development_dependency "guard"
30
+ spec.add_development_dependency "guard-rspec"
31
+ spec.add_development_dependency "rspec-nc"
23
32
  end
data/lib/esa.rb CHANGED
@@ -1,5 +1,5 @@
1
- require "esa/version"
1
+ require "faraday"
2
+ require "faraday_middleware"
2
3
 
3
- module Esa
4
- # Your code goes here...
5
- end
4
+ require "esa/version"
5
+ require "esa/client"
@@ -0,0 +1,40 @@
1
+ module Esa
2
+ module ApiMethods
3
+ def teams(params = nil, headers = nil)
4
+ send_get("/v1/teams", params, headers)
5
+ end
6
+
7
+ def team(name, params = nil, headers = nil)
8
+ send_get("/v1/teams/#{name}", params, headers)
9
+ end
10
+
11
+ def posts(params = nil, headers = nil)
12
+ send_get("/v1/teams/#{current_team}/posts", params, headers)
13
+ end
14
+
15
+ def post(number, params = nil, headers = nil)
16
+ send_get("/v1/teams/#{current_team}/posts/#{number}", params, headers)
17
+ end
18
+
19
+ def create_post(params = nil, headers = nil)
20
+ send_post("/v1/teams/#{current_team}/posts", wrap(params, :post), headers)
21
+ end
22
+
23
+ def update_post(number, params = nil, headers = nil)
24
+ send_patch("/v1/teams/#{current_team}/posts/#{number}", wrap(params, :post), headers)
25
+ end
26
+
27
+ def delete_post(number, params = nil, headers = nil)
28
+ send_delete("/v1/teams/#{current_team}/posts/#{number}", params, headers)
29
+ end
30
+
31
+ private
32
+
33
+ def wrap(params, envelope)
34
+ return params if params.nil?
35
+ return params unless params.is_a?(Hash)
36
+ return params if params.has_key?(envelope.to_sym) || params.has_key?(envelope.to_s)
37
+ { envelope => params }
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,83 @@
1
+ require 'esa/api_methods'
2
+ require "esa/response"
3
+ require 'esa/errors'
4
+
5
+ module Esa
6
+ class Client
7
+ include ApiMethods
8
+
9
+ def initialize(access_token: nil, api_endpoint: nil, current_team: nil)
10
+ @access_token = access_token
11
+ @api_endpoint = api_endpoint
12
+ @current_team = current_team
13
+ end
14
+ attr_writer :current_team
15
+
16
+ def current_team
17
+ raise TeamNotSpecifiedError, "current_team is not specified" unless @current_team
18
+ @current_team
19
+ end
20
+
21
+ def send_get(path, params = nil, headers = nil)
22
+ send_request(:get, path, params, headers)
23
+ end
24
+
25
+ def send_post(path, params = nil, headers = nil)
26
+ send_request(:post, path, params, headers)
27
+ end
28
+
29
+ def send_put(path, params = nil, headers = nil)
30
+ send_request(:put, path, params, headers)
31
+ end
32
+
33
+ def send_patch(path, params = nil, headers = nil)
34
+ send_request(:patch, path, params, headers)
35
+ end
36
+
37
+ def send_delete(path, params = nil, headers = nil)
38
+ send_request(:delete, path, params, headers)
39
+ end
40
+
41
+ def send_request(method, path, params, headers)
42
+ Esa::Response.new(connection.send(method, path, params, headers))
43
+ end
44
+
45
+ def connection
46
+ @connection ||= Faraday.new(faraday_options) do |c|
47
+ c.request :json
48
+ c.response :json
49
+ c.adapter Faraday.default_adapter
50
+ end
51
+ end
52
+
53
+ private
54
+
55
+ def faraday_options
56
+ {
57
+ url: faraday_url,
58
+ headers: faraday_headers,
59
+ # ssl: { verify: !!faraday_url.match(/^https:\/\//) },
60
+ }
61
+ end
62
+
63
+ def default_headers
64
+ {
65
+ 'Accept' => 'application/json',
66
+ 'User-Agent' => "Esa Ruby Gem #{Esa::VERSION}",
67
+ }
68
+ end
69
+
70
+ def faraday_headers
71
+ return default_headers unless access_token
72
+ default_headers.merge(Authorization: "Bearer #{access_token}")
73
+ end
74
+
75
+ def access_token
76
+ @access_token || ENV['ESA_ACCESS_TOKEN']
77
+ end
78
+
79
+ def faraday_url
80
+ @api_endpoint || ENV["ESA_API_ENDPOINT"] || "https://api.esa.io"
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,4 @@
1
+ module Esa
2
+ class EsaError < StandardError; end
3
+ class TeamNotSpecifiedError < EsaError; end
4
+ end
@@ -0,0 +1,23 @@
1
+ module Esa
2
+ class Response
3
+ def initialize(faraday_response)
4
+ @raw_body = faraday_response.body
5
+ @raw_headers = faraday_response.headers
6
+ @raw_status = faraday_response.status
7
+ end
8
+
9
+ def body
10
+ @raw_body
11
+ end
12
+
13
+ def headers
14
+ @headers ||= @raw_headers.headers.inject({}) do |result, (key, value)|
15
+ result.merge(key.split("-").map(&:capitalize).join("-") => value)
16
+ end
17
+ end
18
+
19
+ def status
20
+ @raw_status
21
+ end
22
+ end
23
+ end
@@ -1,3 +1,3 @@
1
1
  module Esa
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,50 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Esa::Client do
4
+ let(:access_token) { nil }
5
+ let(:api_endpoint) { nil }
6
+ let(:current_team) { nil }
7
+ let(:options) do
8
+ {
9
+ access_token: access_token,
10
+ api_endpoint: api_endpoint,
11
+ current_team: current_team,
12
+ }
13
+ end
14
+ subject(:client) { described_class.new(options) }
15
+
16
+ describe "#current_team" do
17
+ context 'team not specified' do
18
+ it 'raise error' do
19
+ expect do
20
+ client.current_team
21
+ end.to raise_error Esa::TeamNotSpecifiedError
22
+ end
23
+ end
24
+
25
+ context 'team specified' do
26
+ let(:current_team) { '<team>' }
27
+ it 'return current_team' do
28
+ expect(client.current_team).to eq current_team
29
+ end
30
+ end
31
+ end
32
+
33
+ %i(get post put patch delete).each do |method|
34
+ describe "#send_#{method}" do
35
+ let(:path) { '<path>' }
36
+ let(:params) { '<params>' }
37
+ let(:headers) { '<headers>' }
38
+ it "call send_request with method, path, params and headers" do
39
+ expect(client).to receive(:send_request).with(method, path, params, headers)
40
+ client.__send__("send_#{method}", path, params, headers)
41
+ end
42
+ end
43
+ end
44
+
45
+ # describe "#send_request", :vcr do
46
+ # it 'returns Esa::Response' do
47
+ # expect(client.teams).to be_a Esa::Response
48
+ # end
49
+ # end
50
+ end
@@ -0,0 +1,35 @@
1
+ require 'esa'
2
+ require 'webmock/rspec'
3
+ require 'vcr'
4
+
5
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
6
+ RSpec.configure do |config|
7
+ config.expect_with :rspec do |expectations|
8
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
9
+ end
10
+
11
+ config.mock_with :rspec do |mocks|
12
+ mocks.verify_partial_doubles = true
13
+ end
14
+
15
+ config.filter_run :focus
16
+ config.run_all_when_everything_filtered = true
17
+
18
+ config.disable_monkey_patching!
19
+ config.warnings = true
20
+
21
+ if config.files_to_run.one?
22
+ config.default_formatter = 'doc'
23
+ end
24
+
25
+ config.profile_examples = 10
26
+ config.order = :random
27
+ Kernel.srand config.seed
28
+ end
29
+
30
+ VCR.configure do |c|
31
+ c.cassette_library_dir = 'spec/cassettes'
32
+ c.hook_into :webmock
33
+ c.configure_rspec_metadata!
34
+ c.filter_sensitive_data('<ACCESS_TOKEN>') { ENV['ESA_ACCESS_TOKEN'] }
35
+ end
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: esa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - fukayatsu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-22 00:00:00.000000000 Z
11
+ date: 2015-05-10 00:00:00.000000000 Z
12
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'
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: bundler
15
43
  requirement: !ruby/object:Gem::Requirement
@@ -38,7 +66,105 @@ dependencies:
38
66
  - - "~>"
39
67
  - !ruby/object:Gem::Version
40
68
  version: '10.0'
41
- description: "( ⁰⊖⁰): Write a longer description. Optional."
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
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
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: vcr
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: guard
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: guard-rspec
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rspec-nc
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ description: "([WIP] esa API v2 client library, written in Ruby"
42
168
  email:
43
169
  - fukayatsu@gmail.com
44
170
  executables: []
@@ -46,14 +172,22 @@ extensions: []
46
172
  extra_rdoc_files: []
47
173
  files:
48
174
  - ".gitignore"
175
+ - ".rspec"
49
176
  - Gemfile
177
+ - Guardfile
50
178
  - LICENSE.txt
51
179
  - README.md
52
180
  - Rakefile
53
181
  - esa.gemspec
54
182
  - lib/esa.rb
183
+ - lib/esa/api_methods.rb
184
+ - lib/esa/client.rb
185
+ - lib/esa/errors.rb
186
+ - lib/esa/response.rb
55
187
  - lib/esa/version.rb
56
- homepage: ''
188
+ - spec/esa/client_spec.rb
189
+ - spec/spec_helper.rb
190
+ homepage: https://github.com/esaio/esa-ruby/
57
191
  licenses:
58
192
  - MIT
59
193
  metadata: {}
@@ -76,6 +210,8 @@ rubyforge_project:
76
210
  rubygems_version: 2.4.5
77
211
  signing_key:
78
212
  specification_version: 4
79
- summary: "( ⁰⊖⁰): Write a short summary. Required."
80
- test_files: []
213
+ summary: "[WIP] esa API v2 client library, written in Ruby"
214
+ test_files:
215
+ - spec/esa/client_spec.rb
216
+ - spec/spec_helper.rb
81
217
  has_rdoc: