mattermark 0.0.1 → 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.
- checksums.yaml +4 -4
- data/README.md +13 -3
- data/Rakefile +9 -1
- data/lib/mattermark/client/companies.rb +15 -0
- data/lib/mattermark/client.rb +23 -0
- data/lib/mattermark/configuration.rb +24 -0
- data/lib/mattermark/error.rb +7 -0
- data/lib/mattermark/request.rb +29 -0
- data/lib/mattermark/version.rb +1 -1
- data/lib/mattermark.rb +5 -1
- data/mattermark.gemspec +2 -1
- data/test/mattermark/client_test.rb +16 -0
- data/test/mattermark/configuration_test.rb +25 -0
- data/test/test_helper.rb +8 -0
- metadata +41 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2033000ab0347a5e6e5e23c61616a7f2ec3cd9b7
|
4
|
+
data.tar.gz: e2362c8b7f52f7920c19f35b161fbdc9928bde11
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17bf9d98218d1177d1860d80e1d06b51987d72364cbb8ed779e11cf0c6ddfc520be0a06e1dffba6e97122eecf2cbde63d38e16d7dddd8d842ed993ebf3a45f21
|
7
|
+
data.tar.gz: 80d34267b3dcfd5a6d2036c76658e486445dbbb622c240c071f07d7ae8cf4b59ecef1522b613119d279500ed49c946e3d06d7b9b28e3d1856e5313f65d29bf4d
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Mattermark
|
2
2
|
|
3
|
-
|
3
|
+
Ruby client for the mattermark API.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -20,11 +20,21 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
-
|
23
|
+
Mattermark.configure do |c|
|
24
|
+
c.api_key = 'your_api_key'
|
25
|
+
end
|
26
|
+
|
27
|
+
client = Mattermark::Client.new
|
28
|
+
|
29
|
+
begin
|
30
|
+
puts client.companies
|
31
|
+
rescue Mattermark::Forbidden
|
32
|
+
puts "Forbidden!"
|
33
|
+
end
|
24
34
|
|
25
35
|
## Contributing
|
26
36
|
|
27
|
-
1. Fork it ( https://github.com/
|
37
|
+
1. Fork it ( https://github.com/andrewpthorp/mattermark/fork )
|
28
38
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
39
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
40
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/Rakefile
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'mattermark/request'
|
2
|
+
require 'mattermark/configuration'
|
3
|
+
require 'mattermark/client/companies'
|
4
|
+
|
5
|
+
module Mattermark
|
6
|
+
class Client
|
7
|
+
attr_accessor *Mattermark::Configuration::KEYS
|
8
|
+
|
9
|
+
def initialize(opts={})
|
10
|
+
config = Mattermark.configuration.merge(opts)
|
11
|
+
Mattermark::Configuration::KEYS.each do |key|
|
12
|
+
send("#{key}=", config[key])
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def base_url
|
17
|
+
"https://mattermark.com/app/v0/"
|
18
|
+
end
|
19
|
+
|
20
|
+
include Mattermark::Request
|
21
|
+
include Mattermark::Client::Companies
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Mattermark
|
2
|
+
module Configuration
|
3
|
+
|
4
|
+
KEYS = [:api_key]
|
5
|
+
attr_accessor *KEYS
|
6
|
+
|
7
|
+
def self.extended(base)
|
8
|
+
base.reset!
|
9
|
+
end
|
10
|
+
|
11
|
+
def configure
|
12
|
+
yield self
|
13
|
+
end
|
14
|
+
|
15
|
+
def configuration
|
16
|
+
KEYS.inject({}){|o,k| o.merge!(k => send(k)) }
|
17
|
+
end
|
18
|
+
|
19
|
+
def reset!
|
20
|
+
self.api_key = nil
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
|
3
|
+
module Mattermark
|
4
|
+
module Request
|
5
|
+
|
6
|
+
def get(url, params={})
|
7
|
+
RestClient.get(url, build_params(params)) do |resp, req, res, &block|
|
8
|
+
case resp.code
|
9
|
+
when 200
|
10
|
+
JSON.parse(resp)
|
11
|
+
when 403
|
12
|
+
raise Mattermark::Forbidden
|
13
|
+
when 500
|
14
|
+
raise Mattermark::InternalServerError
|
15
|
+
else
|
16
|
+
resp.return!(req, res, &block)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def build_params(params)
|
24
|
+
default_params = { key: self.api_key }
|
25
|
+
{ params: default_params.merge(params) }
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
data/lib/mattermark/version.rb
CHANGED
data/lib/mattermark.rb
CHANGED
data/mattermark.gemspec
CHANGED
@@ -14,10 +14,11 @@ Gem::Specification.new do |spec|
|
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
17
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
18
|
spec.require_paths = ["lib"]
|
20
19
|
|
21
20
|
spec.add_development_dependency "bundler", "~> 1.7"
|
22
21
|
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
+
spec.add_development_dependency "pry"
|
23
|
+
spec.add_runtime_dependency "rest-client", "~> 1.7.2"
|
23
24
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
class Mattermark::ClientTest < Minitest::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@client = Mattermark::Client.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_initializer
|
9
|
+
c = Mattermark::Client.new(api_key: 'foobar')
|
10
|
+
assert_equal 'foobar', c.api_key
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_base_url
|
14
|
+
assert_equal "https://mattermark.com/app/v0/", @client.base_url
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
class Mattermark::ConfigurationTest < MiniTest::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@api_key = 'foobar'
|
6
|
+
Mattermark.configure do |c|
|
7
|
+
c.api_key = @api_key
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_configure
|
12
|
+
client = Mattermark::Client.new
|
13
|
+
assert_equal @api_key, client.api_key
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_configuration
|
17
|
+
assert_equal({ api_key: @api_key }, Mattermark.configuration)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_reset!
|
21
|
+
Mattermark.reset!
|
22
|
+
client = Mattermark::Client.new
|
23
|
+
assert_nil client.api_key
|
24
|
+
end
|
25
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mattermark
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Thorp
|
@@ -38,6 +38,34 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
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: rest-client
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.7.2
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.7.2
|
41
69
|
description: Ruby client for the mattermark API, something something longer.
|
42
70
|
email:
|
43
71
|
- andrewpthorp@gmail.com
|
@@ -51,8 +79,16 @@ files:
|
|
51
79
|
- README.md
|
52
80
|
- Rakefile
|
53
81
|
- lib/mattermark.rb
|
82
|
+
- lib/mattermark/client.rb
|
83
|
+
- lib/mattermark/client/companies.rb
|
84
|
+
- lib/mattermark/configuration.rb
|
85
|
+
- lib/mattermark/error.rb
|
86
|
+
- lib/mattermark/request.rb
|
54
87
|
- lib/mattermark/version.rb
|
55
88
|
- mattermark.gemspec
|
89
|
+
- test/mattermark/client_test.rb
|
90
|
+
- test/mattermark/configuration_test.rb
|
91
|
+
- test/test_helper.rb
|
56
92
|
homepage: https://github.com/andrewpthorp/mattermark
|
57
93
|
licenses:
|
58
94
|
- MIT
|
@@ -77,4 +113,7 @@ rubygems_version: 2.2.2
|
|
77
113
|
signing_key:
|
78
114
|
specification_version: 4
|
79
115
|
summary: Ruby client for the mattermark API.
|
80
|
-
test_files:
|
116
|
+
test_files:
|
117
|
+
- test/mattermark/client_test.rb
|
118
|
+
- test/mattermark/configuration_test.rb
|
119
|
+
- test/test_helper.rb
|