next_erp_bridge 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/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/README.md +65 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/next_erp_bridge/core/client.rb +25 -0
- data/lib/next_erp_bridge/core/core.rb +11 -0
- data/lib/next_erp_bridge/core/credentials.rb +15 -0
- data/lib/next_erp_bridge/core/doctypes.rb +11 -0
- data/lib/next_erp_bridge/core/entry.rb +125 -0
- data/lib/next_erp_bridge/core/frappe_client.rb +150 -0
- data/lib/next_erp_bridge/core/util.rb +25 -0
- data/lib/next_erp_bridge/entity/base.rb +33 -0
- data/lib/next_erp_bridge/entity/entity.rb +59 -0
- data/lib/next_erp_bridge/version.rb +3 -0
- data/lib/next_erp_bridge.rb +13 -0
- data/next_erp_bridge.gemspec +35 -0
- metadata +132 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fc8d312651006eedc6f93ffba513b3b626b42b98
|
4
|
+
data.tar.gz: ae633113c83040f944202eaf048b7f818e5fae57
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ff14be35cfe8856c0b020e26d3a71068438fd30b97fa29be76d98dd24b30fd155b4e7459b980b19efa573272541d6b05969af8eb6d60461a90d699686af1a66c
|
7
|
+
data.tar.gz: 1463a86fb4ed38e2cfad4c81b9802c2d41cad6178ef5bacea31908caafca299f82c30a431f4e7eb88c80d8e2d07e0d815718e4583682b786e5802706447ea36e
|
data/.gitignore
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at abhisheksarka@gmail.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# NextErpBridge
|
2
|
+
|
3
|
+
Provides CRUD operations for all default/custom Doctypes in NextErp and provides a wrapper on top of it as well like ActiveRecord Models. Instead of communicating through the API directly you should use this gem since it provides better interfaces and cleaner implementation
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'next_erp_bridge'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
### Configure the gem in an initializer file as follows
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
NextErpBridge.configure do | c |
|
23
|
+
c.host = "https://erp.nestaway.com"
|
24
|
+
c.username = "some.user@nestaway.com"
|
25
|
+
c.password = "password"
|
26
|
+
end
|
27
|
+
```
|
28
|
+
|
29
|
+
### Register the DocTypes that you want to do CRUD on
|
30
|
+
|
31
|
+
You can add DocTypes you want to communicate with using the following
|
32
|
+
```ruby
|
33
|
+
NextErpBridge::Core::Doctypes.supported.merge!({
|
34
|
+
Customer: 'Customer',
|
35
|
+
SalesInvoice: 'Sales Invoice'
|
36
|
+
})
|
37
|
+
# The hash key is used to generate class names within this gem
|
38
|
+
# The value is the value of the Doctype in the ERP system
|
39
|
+
```
|
40
|
+
|
41
|
+
### CRUD on any of the registered DocTypes
|
42
|
+
```ruby
|
43
|
+
user = NextErpBridge::Entity::User.create({first_name: 'Foo'})
|
44
|
+
user.update(last_name: 'Bar')
|
45
|
+
|
46
|
+
sales_invoice = NextErpBridge::Entity::SalesInvoice.find('a23252b')
|
47
|
+
|
48
|
+
sales_invoice.name = "Some Random Name"
|
49
|
+
sales_invoice.save
|
50
|
+
|
51
|
+
c = NextErpBridge::Entity::Customer.find_by({customer_name: 'Foo Bar'})
|
52
|
+
c.customer_name = nil
|
53
|
+
c.save # false
|
54
|
+
c.errors # error string returned by the ERP
|
55
|
+
```
|
56
|
+
|
57
|
+
## Development
|
58
|
+
|
59
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
60
|
+
|
61
|
+
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).
|
62
|
+
|
63
|
+
## Contributing
|
64
|
+
|
65
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/next_erp_bridge. 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.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "next_erp_bridge"
|
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
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
module NextErpBridge
|
4
|
+
module Core
|
5
|
+
class Client
|
6
|
+
include Singleton
|
7
|
+
|
8
|
+
attr_accessor :frappe_client,
|
9
|
+
:credentials
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@credentials = Credentials
|
13
|
+
@frappe_client = FrappeClient.new(
|
14
|
+
credentials.host,
|
15
|
+
credentials.username,
|
16
|
+
credentials.password
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
def login
|
21
|
+
@frappe_client.login(credentials.username, credentials.password)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'active_support'
|
3
|
+
require 'active_support/core_ext'
|
4
|
+
|
5
|
+
module NextErpBridge
|
6
|
+
module Core
|
7
|
+
module Entry
|
8
|
+
|
9
|
+
def self.included(base)
|
10
|
+
base.send(:extend, ClassMethods)
|
11
|
+
base.send(:include, InstanceMethods)
|
12
|
+
end
|
13
|
+
|
14
|
+
module ClassMethods
|
15
|
+
# All methods call this so that we can do a login
|
16
|
+
# before we actually start CRUD in the ERP
|
17
|
+
# As of now for every call it is calling login
|
18
|
+
# which is bad
|
19
|
+
# TODO: Need to change this to, login when session expires
|
20
|
+
def before_action(c={login: true})
|
21
|
+
Client.instance.login if c[:login]
|
22
|
+
end
|
23
|
+
|
24
|
+
def client
|
25
|
+
Client.instance.frappe_client
|
26
|
+
end
|
27
|
+
|
28
|
+
def doctype
|
29
|
+
@doctype
|
30
|
+
end
|
31
|
+
|
32
|
+
def encoded_doctype
|
33
|
+
doctype
|
34
|
+
end
|
35
|
+
|
36
|
+
def create(attrs)
|
37
|
+
before_action
|
38
|
+
a = attrs.merge({ doctype: encoded_doctype })
|
39
|
+
Util.instance_create(self, client.insert(a), a)
|
40
|
+
end
|
41
|
+
|
42
|
+
def find(id, do_login=true)
|
43
|
+
before_action(login: do_login)
|
44
|
+
res = client.fetch_single_record({doctype: encoded_doctype, id: id})
|
45
|
+
d = res['data']
|
46
|
+
self.new(d) if d.present?
|
47
|
+
end
|
48
|
+
|
49
|
+
def all(limit_start=0, limit_page_length=0, do_login=true)
|
50
|
+
before_action(login: do_login)
|
51
|
+
res = client.fetch({doctype: encoded_doctype}, [ ], ["*"], limit_start, limit_page_length)
|
52
|
+
if res['data'].present?
|
53
|
+
res['data'].map { | r | self.new(r) }
|
54
|
+
else
|
55
|
+
[ ]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def find_by(params)
|
60
|
+
before_action
|
61
|
+
filters = [[doctype]]
|
62
|
+
params.each { | k, v | filters[0].concat([k.to_s, '=', v]) }
|
63
|
+
res = client.fetch({ doctype: encoded_doctype }, filters)
|
64
|
+
data = res['data']
|
65
|
+
if data.present?
|
66
|
+
find(data.first['name'], false)
|
67
|
+
else
|
68
|
+
data
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
module InstanceMethods
|
74
|
+
attr_accessor :errors
|
75
|
+
|
76
|
+
def client
|
77
|
+
self.class.client
|
78
|
+
end
|
79
|
+
|
80
|
+
def before_action
|
81
|
+
self.class.before_action
|
82
|
+
end
|
83
|
+
|
84
|
+
def doctype
|
85
|
+
self.class.doctype
|
86
|
+
end
|
87
|
+
|
88
|
+
def encoded_doctype
|
89
|
+
self.class.encoded_doctype
|
90
|
+
end
|
91
|
+
|
92
|
+
def update(attrs)
|
93
|
+
before_action
|
94
|
+
attrs.merge!({ doctype: encoded_doctype, id: attributes['name'] })
|
95
|
+
Util.instance_update(self, client.update(attrs))
|
96
|
+
!errors.present?
|
97
|
+
end
|
98
|
+
|
99
|
+
def rename(new_name, force=false, merge=false, ignore_permissions=false)
|
100
|
+
before_action
|
101
|
+
res = client.api_method('frappe.model.rename_doc.rename_doc', {
|
102
|
+
doctype: doctype,
|
103
|
+
old: self.name,
|
104
|
+
new: new_name,
|
105
|
+
force: force,
|
106
|
+
merge: merge,
|
107
|
+
ignore_permissions: ignore_permissions
|
108
|
+
})
|
109
|
+
if res && res['message']
|
110
|
+
self.name = res['message']
|
111
|
+
else
|
112
|
+
false
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def save
|
117
|
+
before_action
|
118
|
+
|
119
|
+
Util.instance_update(self, client.update(attributes.merge(id: attributes['name'], doctype: encoded_doctype)))
|
120
|
+
!errors.present?
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
@@ -0,0 +1,150 @@
|
|
1
|
+
# This code has been imported from https://github.com/NestAway/frappe-client(not authored by me)
|
2
|
+
# to remove dependency on the gem.
|
3
|
+
# TODO: Refactoring required
|
4
|
+
|
5
|
+
require 'httparty'
|
6
|
+
|
7
|
+
module NextErpBridge
|
8
|
+
module Core
|
9
|
+
class FrappeClient
|
10
|
+
include HTTParty
|
11
|
+
|
12
|
+
attr_accessor :url,
|
13
|
+
:session_cookie,
|
14
|
+
:username,
|
15
|
+
:password
|
16
|
+
|
17
|
+
def initialize(opt_url=nil, opt_username=nil, opt_password=nil)
|
18
|
+
self.url = opt_url || ERPNEXT_CONFIG["host_url"]
|
19
|
+
self.username = opt_username || ERPNEXT_CONFIG["username"]
|
20
|
+
self.password = opt_password || ERPNEXT_CONFIG["password"]
|
21
|
+
end
|
22
|
+
|
23
|
+
def login(username, password)
|
24
|
+
action = "api/method/login"
|
25
|
+
login_url = File.join(self.url, action)
|
26
|
+
response = HTTParty.post(login_url, :body => {usr: username, pwd: password})
|
27
|
+
self.session_cookie = "sid=#{parse_set_cookie(response.headers["set-cookie"])["sid"]}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def get_all_doc_types
|
31
|
+
# action =
|
32
|
+
end
|
33
|
+
|
34
|
+
def get_authenticated_user
|
35
|
+
action = "api/method/frappe.auth.get_logged_user"
|
36
|
+
login_url = File.join(self.url, action)
|
37
|
+
response = HTTParty.get(login_url, :headers => {
|
38
|
+
"Cookie" => self.session_cookie, "Content-Type" => "application/json",
|
39
|
+
"Accept" => "application/json", "X-Frappe-CSRF-Token" => self.session_cookie
|
40
|
+
})
|
41
|
+
return response.parsed_response
|
42
|
+
end
|
43
|
+
|
44
|
+
def parse_set_cookie(all_cookies_string)
|
45
|
+
cookies = Hash.new
|
46
|
+
|
47
|
+
if !all_cookies_string.empty?
|
48
|
+
all_cookies_string.split(',').each do |single_cookie_string|
|
49
|
+
cookie_part_string = single_cookie_string.strip.split(';')[0]
|
50
|
+
cookie_part = cookie_part_string.strip.split('=')
|
51
|
+
key = cookie_part[0]
|
52
|
+
value = cookie_part[1]
|
53
|
+
|
54
|
+
cookies[key] = value
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
cookies
|
59
|
+
end
|
60
|
+
|
61
|
+
# This method is used to fetch more than one record
|
62
|
+
# Example Response {"data"=>[{"name"=>"LEAD-00420"}, {"name"=>"LEAD-00419"}}
|
63
|
+
|
64
|
+
# filters should be set in this format [{doctype}, {field}, {operator}, {operand}]
|
65
|
+
# searching for Lead with email id ravi.lakhotia@nestaway.com : filters = [["Lead","email_id","=","ravi.lakhotia@nestaway.com"]]
|
66
|
+
|
67
|
+
# fields : fields from the docType required in response. default is only name
|
68
|
+
# fields can be set as follows : ["name","email_id"]
|
69
|
+
|
70
|
+
def fetch(data, filters=[], fields=[], limit_start=0, limit_page_length=20)
|
71
|
+
url_path = self.url + "/api/resource/" + data[:doctype] + "?filters=#{filters}&fields=#{fields}&limit_start=#{limit_start}&limit_page_length=#{limit_page_length}"
|
72
|
+
encoded_url_path = URI.encode url_path
|
73
|
+
|
74
|
+
response = HTTParty.get(encoded_url_path, :headers => {
|
75
|
+
"Cookie" => self.session_cookie, "Accept" => "application/json",
|
76
|
+
"X-Frappe-CSRF-Token" => self.session_cookie
|
77
|
+
})
|
78
|
+
return response.parsed_response
|
79
|
+
end
|
80
|
+
|
81
|
+
# To fetch all the details from ERP for single record
|
82
|
+
# Example log in login_url = "https://nest.erpnext.com/api/resource/Lead/LEAD-00420"
|
83
|
+
def fetch_single_record(data)
|
84
|
+
url_path = self.url + "/api/resource/" + data[:doctype] + "/" + data[:id]
|
85
|
+
encoded_url_path = URI.encode url_path
|
86
|
+
|
87
|
+
response = HTTParty.get(encoded_url_path, :headers => {
|
88
|
+
"Cookie" => self.session_cookie, "Accept" => "application/json",
|
89
|
+
"X-Frappe-CSRF-Token" => self.session_cookie
|
90
|
+
})
|
91
|
+
return response.parsed_response
|
92
|
+
end
|
93
|
+
|
94
|
+
def insert(data)
|
95
|
+
url_path = self.url + "/api/resource/" + data[:doctype]
|
96
|
+
encoded_url_path = URI.encode url_path
|
97
|
+
|
98
|
+
response = HTTParty.post(encoded_url_path, :headers => {
|
99
|
+
"Cookie" => self.session_cookie, "Accept" => "application/json",
|
100
|
+
"X-Frappe-CSRF-Token" => self.session_cookie,
|
101
|
+
"application/x-www-form-urlencoded" => "multipart/form-data"
|
102
|
+
}, :body => {:data => data.to_json})
|
103
|
+
return response.parsed_response
|
104
|
+
end
|
105
|
+
|
106
|
+
def update(data)
|
107
|
+
url_path = self.url + "/api/resource/" + data[:doctype] + "/" + data[:id]
|
108
|
+
encoded_url_path = URI.encode url_path
|
109
|
+
|
110
|
+
response = HTTParty.put(encoded_url_path, :headers => {
|
111
|
+
"Cookie" => self.session_cookie, "Accept" => "application/json",
|
112
|
+
"X-Frappe-CSRF-Token" => self.session_cookie,
|
113
|
+
"application/x-www-form-urlencoded" => "multipart/form-data"
|
114
|
+
}, :body => {:data => data.to_json})
|
115
|
+
return response.parsed_response
|
116
|
+
end
|
117
|
+
|
118
|
+
def api_method(method_name, params)
|
119
|
+
url_path = self.url + "/api/method/" + method_name
|
120
|
+
encoded_url_path = URI.encode url_path
|
121
|
+
|
122
|
+
response = HTTParty.post(encoded_url_path, :headers => {
|
123
|
+
"Cookie" => self.session_cookie, "Accept" => "application/json",
|
124
|
+
"X-Frappe-CSRF-Token" => self.session_cookie,
|
125
|
+
"application/x-www-form-urlencoded" => "multipart/form-data"
|
126
|
+
}, :body => params)
|
127
|
+
return response.parsed_response
|
128
|
+
end
|
129
|
+
|
130
|
+
# This method can be used to call any raw api supported by frappe/erpnext
|
131
|
+
|
132
|
+
def raw_api(url, request_type, params)
|
133
|
+
url_path = self.url + url
|
134
|
+
encoded_url_path = URI.encode url_path
|
135
|
+
if request_type == "Get"
|
136
|
+
response = HTTParty.get(encoded_url_path, :headers => {
|
137
|
+
"Cookie" => self.session_cookie, "Accept" => "application/json",
|
138
|
+
"X-Frappe-CSRF-Token" => self.session_cookie
|
139
|
+
})
|
140
|
+
else
|
141
|
+
response = HTTParty.post(encoded_url_path, :headers => {
|
142
|
+
"Cookie" => self.session_cookie, "Accept" => "application/json",
|
143
|
+
"X-Frappe-CSRF-Token" => self.session_cookie,
|
144
|
+
"Content-Type" => "application/x-www-form-urlencoded" }, :body => params)
|
145
|
+
end
|
146
|
+
return response.parsed_response
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module NextErpBridge
|
2
|
+
module Core
|
3
|
+
module Util
|
4
|
+
def self.instance_create(klass, res, attrs=nil)
|
5
|
+
if res['data']
|
6
|
+
instance = klass.new(res['data'])
|
7
|
+
else
|
8
|
+
instance = klass.new(attrs)
|
9
|
+
instance.errors = res['exc']
|
10
|
+
end
|
11
|
+
instance
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.instance_update(instance, res)
|
15
|
+
if res['data']
|
16
|
+
instance.errors = nil
|
17
|
+
instance.attributes = res['data']
|
18
|
+
else
|
19
|
+
instance.errors = res['exc']
|
20
|
+
end
|
21
|
+
instance
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module NextErpBridge
|
2
|
+
module Entity
|
3
|
+
class Base
|
4
|
+
@@klass_registry = { }
|
5
|
+
|
6
|
+
include Core::Entry
|
7
|
+
attr_accessor :attributes
|
8
|
+
|
9
|
+
def initialize(attributes)
|
10
|
+
@attributes = attributes
|
11
|
+
end
|
12
|
+
|
13
|
+
def method_missing(m, *args, &block)
|
14
|
+
keys = attributes.keys.map(&:to_s)
|
15
|
+
m = m.to_s
|
16
|
+
is_setter = (m[-1] == '=')
|
17
|
+
if is_setter
|
18
|
+
m = m[0..(m.size-2)]
|
19
|
+
end
|
20
|
+
if keys.include?(m)
|
21
|
+
attributes[m] = args[0] if is_setter
|
22
|
+
attributes[m]
|
23
|
+
else
|
24
|
+
super(m.to_sym, *args)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.klass_registry
|
29
|
+
@@klass_registry
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require_relative './base'
|
2
|
+
|
3
|
+
module NextErpBridge
|
4
|
+
module Entity
|
5
|
+
##
|
6
|
+
# Dynamically creates class to access the ERP API
|
7
|
+
#
|
8
|
+
# Class and doctype should be defined in Core::Doctypes.supported
|
9
|
+
#
|
10
|
+
# If defined, you can call methods 'create', 'update', 'destroy' and 'find'
|
11
|
+
#
|
12
|
+
# For e.g NextErpBridge::Entity::Journal.create(attrs) assuming
|
13
|
+
# Journal is defined in Core::Doctypes.supported
|
14
|
+
#
|
15
|
+
# If basic CRUD is not enough on the class(Journal in this case) you can create
|
16
|
+
# a new class of inside the Entity module and inherit the base class and define a
|
17
|
+
# doctype on it and other methods needed
|
18
|
+
#
|
19
|
+
# module NextErpBridge
|
20
|
+
# module Entity
|
21
|
+
# class Journal < Base
|
22
|
+
# @doctype = 'Journal%20Entry'
|
23
|
+
# def some_custom_method
|
24
|
+
# end
|
25
|
+
# end
|
26
|
+
# end
|
27
|
+
# end
|
28
|
+
#
|
29
|
+
##
|
30
|
+
|
31
|
+
def self.const_missing(name)
|
32
|
+
klass_name = name
|
33
|
+
doctype_name = Core::Doctypes.supported[klass_name]
|
34
|
+
if doctype_name
|
35
|
+
registry = Base.klass_registry
|
36
|
+
|
37
|
+
# Check if the class has been created already
|
38
|
+
# This is to prevent creation of multiple
|
39
|
+
# versions of the same class object
|
40
|
+
klass = registry[doctype_name]
|
41
|
+
|
42
|
+
# If it is not present create an anonymous class
|
43
|
+
# and add it to the registry
|
44
|
+
if klass.blank?
|
45
|
+
klass = Class.new(Base) do
|
46
|
+
|
47
|
+
end
|
48
|
+
registry[doctype_name] = klass
|
49
|
+
end
|
50
|
+
|
51
|
+
# Do stuff on the class and return the class instance
|
52
|
+
klass.instance_variable_set(:@doctype, doctype_name)
|
53
|
+
klass
|
54
|
+
else
|
55
|
+
super
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "next_erp_bridge/version"
|
2
|
+
require "next_erp_bridge/core/core"
|
3
|
+
require "next_erp_bridge/entity/entity"
|
4
|
+
|
5
|
+
module NextErpBridge
|
6
|
+
# Your code goes here...
|
7
|
+
class << self
|
8
|
+
def configure
|
9
|
+
yield(Core::Credentials)
|
10
|
+
Core::Client.instance
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'next_erp_bridge/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "next_erp_bridge"
|
8
|
+
spec.version = NextErpBridge::VERSION
|
9
|
+
spec.authors = ["abhisheksarka"]
|
10
|
+
spec.email = ["abhisheksarka@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{CRUD API for NextErp Doctypes}
|
13
|
+
spec.description = %q{Provides CRUD operations for all default/custom Doctypes in NextErp}
|
14
|
+
spec.homepage = "https://github.com/NestAway/next_erp_bridge/"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
17
|
+
# delete this section to allow pushing this gem to any host.
|
18
|
+
# if spec.respond_to?(:metadata)
|
19
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
20
|
+
# else
|
21
|
+
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
22
|
+
# end
|
23
|
+
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
30
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
31
|
+
spec.add_development_dependency "pry"
|
32
|
+
|
33
|
+
spec.add_dependency 'activesupport', "< 5.0"
|
34
|
+
spec.add_dependency 'httparty'
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: next_erp_bridge
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- abhisheksarka
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-08-22 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.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
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: 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: activesupport
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "<"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5.0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "<"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: httparty
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Provides CRUD operations for all default/custom Doctypes in NextErp
|
84
|
+
email:
|
85
|
+
- abhisheksarka@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- CODE_OF_CONDUCT.md
|
92
|
+
- Gemfile
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- bin/console
|
96
|
+
- bin/setup
|
97
|
+
- lib/next_erp_bridge.rb
|
98
|
+
- lib/next_erp_bridge/core/client.rb
|
99
|
+
- lib/next_erp_bridge/core/core.rb
|
100
|
+
- lib/next_erp_bridge/core/credentials.rb
|
101
|
+
- lib/next_erp_bridge/core/doctypes.rb
|
102
|
+
- lib/next_erp_bridge/core/entry.rb
|
103
|
+
- lib/next_erp_bridge/core/frappe_client.rb
|
104
|
+
- lib/next_erp_bridge/core/util.rb
|
105
|
+
- lib/next_erp_bridge/entity/base.rb
|
106
|
+
- lib/next_erp_bridge/entity/entity.rb
|
107
|
+
- lib/next_erp_bridge/version.rb
|
108
|
+
- next_erp_bridge.gemspec
|
109
|
+
homepage: https://github.com/NestAway/next_erp_bridge/
|
110
|
+
licenses: []
|
111
|
+
metadata: {}
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
requirements: []
|
127
|
+
rubyforge_project:
|
128
|
+
rubygems_version: 2.4.3
|
129
|
+
signing_key:
|
130
|
+
specification_version: 4
|
131
|
+
summary: CRUD API for NextErp Doctypes
|
132
|
+
test_files: []
|