paw_client 0.0.1 → 0.0.2

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
  SHA1:
3
- metadata.gz: 79ed6e5658036c9227edfc600799f41f34f47b3c
4
- data.tar.gz: 753319ecb8561553e7d6a74a95fe0638c3f0e8dd
3
+ metadata.gz: 59a277531b3bba6cf3141155edd7294d64d1cf5d
4
+ data.tar.gz: be130de5fc365d3b458a2ea02c08ebc8e7d4ff50
5
5
  SHA512:
6
- metadata.gz: 0712b1dde15a30f96df9ef2f7c9109ccf5f479d50d47a3066bef229b2dcc9e82da2285a2bbe629793d64f24346a70c0d87bef015353074bd6c6e7aeea6f6c916
7
- data.tar.gz: 65bd246990dff30a4e7d1829e0fd1e59fdeeb24d79b7e3834a3ee7c9e2079d6b1e057fb977d9c032eec207d19fbe445e30306ac08886bd899e5b4cc76d5a025d
6
+ metadata.gz: ecac9efe22bcc698bee34fcd67ac6ec2cb798b3ad3a7c8674446b102b24acbcef3cc17fd2aa7d57f332331da4496cbce461bdb4a22315628a45fe2d58e8a0c3d
7
+ data.tar.gz: 73d24408b8a6338213c62a70c912bfd2e879969ce014b84adcd8762a616f5b5a2b77a0630ebc92020a484bf6f14cc5d5d221bba694a4eca3434cb0b0d9245c55
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paw_client
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
  - Olivier DIRRENBERGER
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-03-09 00:00:00.000000000 Z
11
+ date: 2018-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -114,18 +114,7 @@ email:
114
114
  executables: []
115
115
  extensions: []
116
116
  extra_rdoc_files: []
117
- files:
118
- - ".gitignore"
119
- - Gemfile
120
- - LICENCE.txt
121
- - bin/console
122
- - bin/setup
123
- - lib/paw_client.rb
124
- - lib/paw_client/client.rb
125
- - lib/paw_client/configuration.rb
126
- - lib/paw_client/version.rb
127
- - paw_client.gemspec
128
- - travis.yml
117
+ files: []
129
118
  homepage: https://code.plugandwork.net/plugandwork/paw_client
130
119
  licenses:
131
120
  - MIT
data/.gitignore DELETED
@@ -1,14 +0,0 @@
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
13
- config.yml
14
-
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- # Specify your gem's dependencies in paw_client.gemspec
4
- gemspec
data/LICENCE.txt DELETED
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2018 plugandwork
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/bin/console DELETED
@@ -1,20 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "paw_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
-
11
- config_path=File.expand_path("../../config.yml", __FILE__)
12
- if File.exists?(config_path)
13
- PawClient.config=PawClient::Configuration.from_yaml(config_path)
14
- end
15
-
16
- #
17
- require "pry"
18
- Pry.start
19
- # require "irb"
20
- # IRB.start(__FILE__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
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
@@ -1,120 +0,0 @@
1
- require 'rest-client'
2
- require 'base64'
3
- require 'nokogiri'
4
- require 'json'
5
-
6
- class PawClient::Client
7
-
8
- class ClientError < StandardError
9
- attr_reader :response
10
-
11
- def initialize(response)
12
- super(message)
13
- @response = response
14
- message=to_json.success rescue 'Error while call plugandwork API, Unparsable response'
15
- super(message)
16
- end
17
-
18
- def info
19
- to_json.info
20
- end
21
-
22
- def to_json
23
- JSON.parse(self.response.to_s)
24
- end
25
-
26
- def request
27
- self.response.request
28
- end
29
- end
30
-
31
-
32
- attr_accessor :base_url
33
- attr_accessor :uuid
34
- attr_accessor :token
35
- attr_accessor :user_token
36
- attr_accessor :logger
37
-
38
- def initialize(attrs={})
39
- @base_url = attrs.fetch(:base_url, PawClient.config.base_url)
40
- @uuid = attrs.fetch(:uuid, PawClient.config.uuid)
41
- @token = attrs.fetch(:token, PawClient.config.token)
42
- @user_token = attrs.fetch(:token, PawClient.config.user_token)
43
- @logger = attrs.fetch(:logger, PawClient.config.logger)
44
- end
45
-
46
- def endpoint_for(path)
47
- base_resource[path]
48
- end
49
-
50
- def get(path, params={})
51
- begin
52
- r=endpoint_for(path).get(params)
53
- JSON.parse(r.to_s)
54
- rescue RestClient::ExceptionWithResponse => err
55
- raise ClientError.new(err.response)
56
- end
57
- end
58
-
59
- def post(path, payload, params={})
60
- begin
61
- r=endpoint_for(path).post(payload,params)
62
- JSON.parse(r.to_s)
63
- rescue RestClient::ExceptionWithResponse => err
64
- raise ClientError.new(err.response)
65
- end
66
- end
67
-
68
- def delete(path, params={})
69
- begin
70
- r=endpoint_for(path).delete(params)
71
- JSON.parse(r.to_s)
72
- rescue RestClient::ExceptionWithResponse => err
73
- raise ClientError.new(err.response)
74
- end
75
- end
76
-
77
- def create_doc(filepath = nil,params = {})
78
- j = {}
79
- j['doc']=params
80
- j['doc']['title']||=File.basename(filepath) if filepath
81
- res = post('docs', j)
82
- if res && res['id'] && filepath
83
- res = upload_file(filepath, 'id' => res['id'])
84
- end
85
- return res
86
- end
87
-
88
- def delete_doc(id)
89
- delete('docs/'+id )
90
- end
91
-
92
- def upload_file(localpath, params={})
93
- begin
94
- request = RestClient::Request.new(
95
- :method => :post,
96
- :url => @base_url + "/api/d1/docs/#{params['id']}/file",
97
- :payload => {
98
- :multipart => true,
99
- :file => File.new(localpath, 'rb')
100
- },
101
- :headers => {'Accept' => 'application/json', 'Authorization': "Bearer #{@user_token}"}
102
- )
103
- r = request.execute
104
- #RestClient::Resource.new(@base_url + '/api/d1/', headers: {'Authorization': "Bearer #{@user_token}"}, lo
105
- JSON.parse(r.to_s)
106
- rescue RestClient::ExceptionWithResponse => err
107
- raise ClientError.new(err.response)
108
- end
109
- end
110
-
111
- def base_resource(reload=false)
112
- if !@base_resource || reload
113
- @base_resource=RestClient::Resource.new(@base_url + '/api/d1/', headers: {'Authorization': "Bearer #{@user_token}"}, log: self.logger)
114
- end
115
- @base_resource
116
- end
117
-
118
- end
119
-
120
-
@@ -1,43 +0,0 @@
1
- require 'yaml'
2
- class PawClient::Configuration
3
-
4
- attr_accessor :base_url
5
- attr_accessor :uuid
6
- attr_accessor :token
7
- attr_accessor :user_token
8
- attr_accessor :test_mode
9
- attr_accessor :logger
10
-
11
- def logger=(value)
12
- @logger=case value
13
- when String
14
- case value.downcase
15
- when 'stdout'
16
- Logger.new(STDOUT)
17
- when 'stderr'
18
- Logger.new(STDERR)
19
- else
20
- nil
21
- end
22
- else
23
- value
24
- end
25
- end
26
-
27
- def initialize(attrs={})
28
- self.base_url = attrs.fetch(:base_url, nil)
29
- self.uuid = attrs.fetch(:uuid, nil)
30
- self.token = attrs.fetch(:token, nil)
31
- self.user_token = attrs.fetch(:user_token, nil)
32
- self.logger = attrs.fetch(:logger, nil)
33
- self.test_mode = attrs.fetch(:test_mode, false)
34
- end
35
-
36
- def self.from_yaml(path, env=nil)
37
- attrs = YAML.load_file(path)
38
- attrs = attrs[env] if env
39
- sym_attrs=attrs.each_with_object({}) {|(k, v), memo| memo[k.to_sym] = v}
40
- self.new(sym_attrs)
41
- end
42
-
43
- end
@@ -1,3 +0,0 @@
1
- module PawClient
2
- VERSION = "0.0.1"
3
- end
data/lib/paw_client.rb DELETED
@@ -1,22 +0,0 @@
1
- require "paw_client/version"
2
- require "paw_client/configuration"
3
- require "paw_client/client"
4
-
5
- module PawClient
6
-
7
- def self.config(reload=false)
8
- if !@config||reload
9
- @config=Configuration.new
10
- end
11
- @config
12
- end
13
-
14
- def self.config=(value)
15
- @config=value
16
- end
17
-
18
- def self.configure(reload=false)
19
- yield(config(reload))
20
- end
21
-
22
- end
data/paw_client.gemspec DELETED
@@ -1,32 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path("../lib", __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "paw_client/version"
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "paw_client"
8
- spec.version = PawClient::VERSION
9
- spec.authors = ["Olivier DIRRENBERGER"]
10
- spec.email = ["olivier.dirrenberger@plugandwork.fr"]
11
-
12
- spec.summary = "plugandwork ruby API client"
13
- spec.description = "A ruby client for plugandwork API"
14
- spec.homepage = "https://code.plugandwork.net/plugandwork/paw_client"
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.bindir = "exe"
21
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
- spec.require_paths = ["lib"]
23
-
24
- spec.add_dependency "rest-client", "~> 2.0"
25
- spec.add_dependency "nokogiri", "~> 1.8"
26
-
27
- spec.add_development_dependency "bundler", "~> 1.15"
28
- spec.add_development_dependency "rake", "~> 10.0"
29
- spec.add_development_dependency "rspec", "~> 3.0"
30
- spec.add_development_dependency "pry", "~> 0.10"
31
- spec.add_development_dependency "byebug", "~> 9.0"
32
- end
data/travis.yml DELETED
@@ -1,5 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.3.1
5
- before_install: gem install bundler -v 1.15.1