datapi-client 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.rubocop.yml +13 -0
- data/.rubocop_todo.yml +33 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +52 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/bitrise.yml +32 -0
- data/datapi-client.gemspec +26 -0
- data/lib/datapi/client.rb +57 -0
- data/lib/datapi/client/version.rb +5 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4e3f4b1f70f02fb9ad6e04eccd72bbcfe8533875
|
4
|
+
data.tar.gz: 8db1ad921709c0118196262a769ea1144bcb21b0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6e901f37f72392414d63b2d11361d6acb9c6b8f15747e79cb2dca3ccbe3054a170f7cc8dfda1940ce15ff68c82b9b852a21a89577a204121444d7dace5b642e1
|
7
|
+
data.tar.gz: ac2d01192d45e53a7ade2767e2a447d6882a57bc07f65b9f2d5cccfece19fbb4ecdceca5fe4ce1fb59a68b43b98eef9141143f7a5b3a221ab11ee6d0068c098a
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2016-05-01 18:10:59 +0200 using RuboCop version 0.39.0.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 1
|
10
|
+
Metrics/AbcSize:
|
11
|
+
Max: 16
|
12
|
+
|
13
|
+
# Offense count: 1
|
14
|
+
# Cop supports --auto-correct.
|
15
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
16
|
+
# SupportedStyles: braces, no_braces, context_dependent
|
17
|
+
Style/BracesAroundHashParameters:
|
18
|
+
Exclude:
|
19
|
+
- 'lib/datapi/client.rb'
|
20
|
+
|
21
|
+
# Offense count: 2
|
22
|
+
# Cop supports --auto-correct.
|
23
|
+
# Configuration parameters: SupportedStyles, IndentationWidth.
|
24
|
+
# SupportedStyles: special_inside_parentheses, consistent, align_braces
|
25
|
+
Style/IndentHash:
|
26
|
+
EnforcedStyle: consistent
|
27
|
+
|
28
|
+
# Offense count: 1
|
29
|
+
# Cop supports --auto-correct.
|
30
|
+
# Configuration parameters: AllowMultipleReturnValues.
|
31
|
+
Style/RedundantReturn:
|
32
|
+
Exclude:
|
33
|
+
- 'lib/datapi/client.rb'
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Viktor Benei
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# Datapi::Client
|
2
|
+
|
3
|
+
Client for [DatAPI](https://github.com/bitrise-tools/datapi).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'datapi-client'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install datapi-client
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Store data:
|
24
|
+
|
25
|
+
```
|
26
|
+
datapi_store = Datapi::Client::StoreData.new(datapi_root_url, datapi_read_write_api_token)
|
27
|
+
sample_data = { 'label' => 'sample_data', 'value' => true }
|
28
|
+
datapi_store.send(sample_data, 'unit-test')
|
29
|
+
```
|
30
|
+
|
31
|
+
Get data:
|
32
|
+
|
33
|
+
```
|
34
|
+
datapi_get = Datapi::Client::GetData.new(datapi_root_url, datapi_readonly_api_token)
|
35
|
+
datapi_get.get_data_by_typeid('unit-test')
|
36
|
+
```
|
37
|
+
|
38
|
+
## Development
|
39
|
+
|
40
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
41
|
+
|
42
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
43
|
+
|
44
|
+
## Contributing
|
45
|
+
|
46
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/bitrise-tools/datapi-client.
|
47
|
+
|
48
|
+
|
49
|
+
## License
|
50
|
+
|
51
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
52
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "datapi/client"
|
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 "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/bitrise.yml
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
format_version: 1.2.0
|
2
|
+
default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git
|
3
|
+
|
4
|
+
app:
|
5
|
+
envs:
|
6
|
+
# define in .bitrise.secrets.yml
|
7
|
+
- DATAPI_SERVER_URL: $DATAPI_SERVER_URL
|
8
|
+
- DATAPI_READ_WRITE_API_TOKEN: $DATAPI_READ_WRITE_API_TOKEN
|
9
|
+
- DATAPI_READONLY_API_TOKEN: $DATAPI_READONLY_API_TOKEN
|
10
|
+
|
11
|
+
workflows:
|
12
|
+
test:
|
13
|
+
steps:
|
14
|
+
- script:
|
15
|
+
inputs:
|
16
|
+
- content: |-
|
17
|
+
#!/bin/bash
|
18
|
+
set -ex
|
19
|
+
bundle install --with test
|
20
|
+
bundle exec rspec
|
21
|
+
bundle exec rubocop
|
22
|
+
gem-release:
|
23
|
+
description: |-
|
24
|
+
Bump the version number, commit & push it,
|
25
|
+
then run this workflow.
|
26
|
+
steps:
|
27
|
+
- script:
|
28
|
+
inputs:
|
29
|
+
- content: |-
|
30
|
+
#!/bin/bash
|
31
|
+
set -ex
|
32
|
+
rake release
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'datapi/client/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "datapi-client"
|
8
|
+
spec.version = Datapi::Client::VERSION
|
9
|
+
spec.authors = ["Viktor Benei"]
|
10
|
+
spec.email = ["viktor.benei@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Client for DatAPI (https://github.com/bitrise-tools/datapi)}
|
13
|
+
spec.description = %q{Client for DatAPI (https://github.com/bitrise-tools/datapi)}
|
14
|
+
spec.homepage = "https://github.com/bitrise-tools/datapi-client"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "rspec"
|
25
|
+
spec.add_development_dependency "rubocop"
|
26
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'datapi/client/version'
|
2
|
+
require 'json'
|
3
|
+
require 'net/http'
|
4
|
+
|
5
|
+
module Datapi
|
6
|
+
module Client
|
7
|
+
#
|
8
|
+
class StoreData
|
9
|
+
def initialize(datapi_root_url, datapi_read_write_api_token)
|
10
|
+
@datapi_root_url = datapi_root_url
|
11
|
+
@datapi_read_write_api_token = datapi_read_write_api_token
|
12
|
+
end
|
13
|
+
|
14
|
+
def send(data, typeid, generated_at = nil)
|
15
|
+
generated_at = DateTime.now if generated_at.nil?
|
16
|
+
|
17
|
+
uri = URI.join(@datapi_root_url, '/data/', typeid)
|
18
|
+
req = Net::HTTP::Post.new(
|
19
|
+
uri.path,
|
20
|
+
{ 'Content-Type' => 'application/json',
|
21
|
+
'Authorization' => "Token token=#{@datapi_read_write_api_token}"
|
22
|
+
})
|
23
|
+
req.body = { data: data, generated_at: generated_at }.to_json
|
24
|
+
|
25
|
+
res = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme.eql?('https')) do |http|
|
26
|
+
http.request(req)
|
27
|
+
end
|
28
|
+
|
29
|
+
resp_data = JSON.parse(res.body)
|
30
|
+
return resp_data
|
31
|
+
end
|
32
|
+
end
|
33
|
+
#
|
34
|
+
class GetData
|
35
|
+
def initialize(datapi_root_url, datapi_readonly_api_token)
|
36
|
+
@datapi_root_url = datapi_root_url
|
37
|
+
@datapi_readonly_api_token = datapi_readonly_api_token
|
38
|
+
end
|
39
|
+
|
40
|
+
def get_data_by_typeid(typeid)
|
41
|
+
uri = URI.join(@datapi_root_url, '/data/', typeid)
|
42
|
+
req = Net::HTTP::Get.new(
|
43
|
+
uri.path,
|
44
|
+
{ 'Content-Type' => 'application/json',
|
45
|
+
'Authorization' => "Token token=#{@datapi_readonly_api_token}"
|
46
|
+
})
|
47
|
+
|
48
|
+
res = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme.eql?('https')) do |http|
|
49
|
+
http.request(req)
|
50
|
+
end
|
51
|
+
|
52
|
+
resp_data = JSON.parse(res.body)
|
53
|
+
return resp_data
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: datapi-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Viktor Benei
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-05-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
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: rubocop
|
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'
|
69
|
+
description: Client for DatAPI (https://github.com/bitrise-tools/datapi)
|
70
|
+
email:
|
71
|
+
- viktor.benei@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".rubocop.yml"
|
79
|
+
- ".rubocop_todo.yml"
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/console
|
85
|
+
- bin/setup
|
86
|
+
- bitrise.yml
|
87
|
+
- datapi-client.gemspec
|
88
|
+
- lib/datapi/client.rb
|
89
|
+
- lib/datapi/client/version.rb
|
90
|
+
homepage: https://github.com/bitrise-tools/datapi-client
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata: {}
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.4.5.1
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: Client for DatAPI (https://github.com/bitrise-tools/datapi)
|
114
|
+
test_files: []
|