ragic_client 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/CHANGELOG.md +0 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +23 -0
- data/README.md +102 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/ragic_client.rb +130 -0
- data/lib/ragic_client/version.rb +3 -0
- data/ragic_client.gemspec +26 -0
- metadata +56 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 95cef99984d3af55b1dd0cd49407c5220fdc0c775a843517624381dd87526c6c
|
4
|
+
data.tar.gz: e4bf487182f310b08ded26e3545ba015becbea09bfbe20c06bf983573d7ef153
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ecabeae056f53d1b442d5658d607b7f442be551eb0fdde7343c39a97e23e6797925c1e302fc0f872fb114ba4cb35298a9a182eafe4286e42f1fae8d7a95ca161
|
7
|
+
data.tar.gz: d7d10fd25c9b956fb1493fa530d226088a057a17ed2c12228cc78a40d804db826b810e6c6fe51c75015cdbd8c6d5a7ed7f50c0856f0cc7ad74fe3d6b05543c19
|
data/.gitignore
ADDED
data/CHANGELOG.md
ADDED
File without changes
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
ragic_client (0.1.3)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
httparty (0.16.2)
|
10
|
+
multi_xml (>= 0.5.2)
|
11
|
+
multi_xml (0.6.0)
|
12
|
+
rake (12.3.3)
|
13
|
+
|
14
|
+
PLATFORMS
|
15
|
+
ruby
|
16
|
+
|
17
|
+
DEPENDENCIES
|
18
|
+
httparty
|
19
|
+
ragic_client!
|
20
|
+
rake (~> 12.0)
|
21
|
+
|
22
|
+
BUNDLED WITH
|
23
|
+
2.1.4
|
data/README.md
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
# RagicClient
|
2
|
+
|
3
|
+
RagicClient is a simple tool integrate with [Ragic System](https://ragic.com). It's free and quite easy to use :smile: .
|
4
|
+
|
5
|
+
[Ragic HTTP API Integration Guide](https://www.ragic.com/intl/en/doc-api).
|
6
|
+
|
7
|
+
# Features
|
8
|
+
|
9
|
+
- **[Create Entry](#create-entry)**
|
10
|
+
- **[Update Entry](#update-entry)**
|
11
|
+
- **[Delete Entry](#delete-entry)**
|
12
|
+
- **[Find Entry By ID](#find-entry-by-id)**
|
13
|
+
- **[Find Entry By Field ID And Value](#find-entry-by-field-id-and-value)**
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
Add this line to your application's Gemfile:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
gem 'ragic_client'
|
21
|
+
```
|
22
|
+
|
23
|
+
And then execute:
|
24
|
+
|
25
|
+
$ bundle
|
26
|
+
|
27
|
+
Or install it yourself as:
|
28
|
+
|
29
|
+
$ gem install ragic_client
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
### Config
|
34
|
+
|
35
|
+
First thing you need to set up is placing something like this either in initializer or in application.rb file:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
RagicClient.config do |config|
|
39
|
+
config.ragic_api_url = 'your ragic_api_url'
|
40
|
+
config.ragic_api_key = 'Basic your_ragic_api_key'
|
41
|
+
end
|
42
|
+
```
|
43
|
+
|
44
|
+
**Note: What you need to do is use the field ids of the fields as name, and the values that you want to insert as parameter values.**
|
45
|
+
|
46
|
+
See here [Ragic API Documents](https://www.ragic.com/intl/en/doc-api/15/Creating-a-New-Entry).
|
47
|
+
|
48
|
+
### Create Entry
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
params = {
|
52
|
+
'1000001' => 'Project Name',
|
53
|
+
'1000002' => '15000'
|
54
|
+
}
|
55
|
+
RagicClient.create params
|
56
|
+
```
|
57
|
+
|
58
|
+
### Update Entry
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
ragic_id = 1
|
62
|
+
params = {
|
63
|
+
'1000001' => 'Project Name Update'
|
64
|
+
}
|
65
|
+
RagicClient.update ragic_id, params
|
66
|
+
```
|
67
|
+
|
68
|
+
### Delete Entry
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
RagicClient.delete 1
|
72
|
+
```
|
73
|
+
|
74
|
+
### Find Entry by id
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
RagicClient.find 1
|
78
|
+
```
|
79
|
+
|
80
|
+
### Find Entry by field id and value
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
RagicClient.find_by { '1000001' => 'Project Name' }
|
84
|
+
```
|
85
|
+
|
86
|
+
## Development
|
87
|
+
|
88
|
+
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.
|
89
|
+
|
90
|
+
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).
|
91
|
+
|
92
|
+
## Contributing
|
93
|
+
|
94
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ragic_client. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
95
|
+
|
96
|
+
## License
|
97
|
+
|
98
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
99
|
+
|
100
|
+
## Code of Conduct
|
101
|
+
|
102
|
+
Everyone interacting in the EmailDetected project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/ragic_client/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ragic_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(__FILE__)
|
data/bin/setup
ADDED
data/lib/ragic_client.rb
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
require 'ragic_client/version'
|
2
|
+
require 'httparty'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module RagicClient
|
6
|
+
class Error < StandardError; end
|
7
|
+
module Config
|
8
|
+
class << self
|
9
|
+
attr_accessor :ragic_api_url
|
10
|
+
attr_accessor :ragic_api_key
|
11
|
+
|
12
|
+
def setup
|
13
|
+
@ragic_api_url = ragic_api_url
|
14
|
+
@ragic_api_key = ragic_api_key
|
15
|
+
end
|
16
|
+
end
|
17
|
+
self.setup
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.config(&block)
|
21
|
+
if block_given?
|
22
|
+
block.call(RagicClient::Config)
|
23
|
+
else
|
24
|
+
RagicClient::Config
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.ragic_base_api_url(ragic_id = nil)
|
29
|
+
return "#{RagicClient::Config.ragic_api_url}/#{ragic_id}" if ragic_id
|
30
|
+
|
31
|
+
RagicClient::Config.ragic_api_url
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.headers
|
35
|
+
{
|
36
|
+
'Content-Type': 'application/json',
|
37
|
+
'Authorization': RagicClient::Config.ragic_api_key
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.find(ragic_id)
|
42
|
+
opts = {
|
43
|
+
headers: RagicClient.headers
|
44
|
+
}
|
45
|
+
beauty_body HTTParty.get(ragic_base_api_url(ragic_id), opts), ragic_id: ragic_id
|
46
|
+
end
|
47
|
+
|
48
|
+
# https://www.ragic.com/intl/en/doc-api/9/Filter-Conditions
|
49
|
+
def self.find_by(condition_hash = {})
|
50
|
+
opts = {
|
51
|
+
headers: RagicClient.headers
|
52
|
+
}
|
53
|
+
api_url = [ragic_base_api_url]
|
54
|
+
return {
|
55
|
+
status: false,
|
56
|
+
msg: 'Invalid conditions params'
|
57
|
+
} unless condition_hash.is_a?(Hash)
|
58
|
+
index = 0
|
59
|
+
condition_hash.each do |key, value|
|
60
|
+
api_url.push("#{index.zero? ? '?' : '&'}where=#{key},eq,#{value}")
|
61
|
+
index += 1
|
62
|
+
end
|
63
|
+
api_url = api_url.join('')
|
64
|
+
beauty_body HTTParty.get(api_url, opts)
|
65
|
+
end
|
66
|
+
|
67
|
+
# https://www.ragic.com/intl/en/doc-api/20/Deleting-an-entry
|
68
|
+
def self.delete(ragic_id)
|
69
|
+
opts = {
|
70
|
+
headers: RagicClient.headers
|
71
|
+
}
|
72
|
+
beauty_body HTTParty.delete(ragic_base_api_url(ragic_id), opts)
|
73
|
+
end
|
74
|
+
|
75
|
+
# https://www.ragic.com/intl/en/doc-api/15/Creating-a-New-Entry
|
76
|
+
def self.create(params = {})
|
77
|
+
ragic_params = { doDefaultValue: true, doLinkLoad: true }
|
78
|
+
ragic_params = ragic_params.merge!(params)
|
79
|
+
opts = {
|
80
|
+
headers: RagicClient.headers,
|
81
|
+
body: ragic_params.to_json
|
82
|
+
}
|
83
|
+
beauty_body HTTParty.post(ragic_base_api_url, opts)
|
84
|
+
end
|
85
|
+
|
86
|
+
# https://www.ragic.com/intl/en/doc-api/16/Modifying-an-Entry
|
87
|
+
def self.update(ragic_id, params = {})
|
88
|
+
opts = {
|
89
|
+
headers: RagicClient.headers,
|
90
|
+
body: params.to_json
|
91
|
+
}
|
92
|
+
beauty_body HTTParty.post(ragic_base_api_url(ragic_id), opts), is_update: true
|
93
|
+
end
|
94
|
+
|
95
|
+
def self.beauty_body(response, options = {})
|
96
|
+
success = false
|
97
|
+
status_code = response.code
|
98
|
+
if status_code == 200
|
99
|
+
begin
|
100
|
+
body = JSON.parse(response.body) || {}
|
101
|
+
data =
|
102
|
+
if options[:is_update]
|
103
|
+
body['data']
|
104
|
+
elsif options[:ragic_id]
|
105
|
+
body[options[:ragic_id].to_s]
|
106
|
+
else
|
107
|
+
body
|
108
|
+
end
|
109
|
+
success = true if body['status'] != 'ERROR'
|
110
|
+
msg = 'Ragic ID Not Found.' if ragic_id
|
111
|
+
msg = body['msg']&.gsub(' ', '') if data
|
112
|
+
rescue
|
113
|
+
msg = 'Error!'
|
114
|
+
end
|
115
|
+
else
|
116
|
+
begin
|
117
|
+
body = JSON.parse(response.body)
|
118
|
+
msg = body['msg']&.gsub(' ', '')
|
119
|
+
rescue
|
120
|
+
msg = 'Error!'
|
121
|
+
end
|
122
|
+
end
|
123
|
+
{
|
124
|
+
status_code: status_code,
|
125
|
+
success: success,
|
126
|
+
data: data,
|
127
|
+
msg: msg
|
128
|
+
}.delete_if { |_k, v| v.nil? }
|
129
|
+
end
|
130
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require_relative 'lib/ragic_client/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "ragic_client"
|
5
|
+
spec.version = RagicClient::VERSION
|
6
|
+
spec.authors = ["Derek Nguyen"]
|
7
|
+
spec.email = ["derek.nguyen.269@gmail.com"]
|
8
|
+
|
9
|
+
spec.summary = 'RagicClient'
|
10
|
+
spec.description = 'RagicClient is a simple tool integrate with RAGIC system.'
|
11
|
+
spec.homepage = "https://github.com/dereknguyen269/ragic_client"
|
12
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
13
|
+
|
14
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
15
|
+
spec.metadata["source_code_uri"] = "https://github.com/dereknguyen269/ragic_client"
|
16
|
+
spec.metadata["changelog_uri"] = "https://github.com/dereknguyen269/ragic_client/CHANGELOG.md"
|
17
|
+
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
21
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
end
|
23
|
+
spec.bindir = "exe"
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ragic_client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Derek Nguyen
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-05-31 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: RagicClient is a simple tool integrate with RAGIC system.
|
14
|
+
email:
|
15
|
+
- derek.nguyen.269@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".gitignore"
|
21
|
+
- CHANGELOG.md
|
22
|
+
- Gemfile
|
23
|
+
- Gemfile.lock
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- bin/console
|
27
|
+
- bin/setup
|
28
|
+
- lib/ragic_client.rb
|
29
|
+
- lib/ragic_client/version.rb
|
30
|
+
- ragic_client.gemspec
|
31
|
+
homepage: https://github.com/dereknguyen269/ragic_client
|
32
|
+
licenses: []
|
33
|
+
metadata:
|
34
|
+
homepage_uri: https://github.com/dereknguyen269/ragic_client
|
35
|
+
source_code_uri: https://github.com/dereknguyen269/ragic_client
|
36
|
+
changelog_uri: https://github.com/dereknguyen269/ragic_client/CHANGELOG.md
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options: []
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.3.0
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
requirements: []
|
52
|
+
rubygems_version: 3.1.2
|
53
|
+
signing_key:
|
54
|
+
specification_version: 4
|
55
|
+
summary: RagicClient
|
56
|
+
test_files: []
|