This repository has been archived by the owner on May 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor: Move client into issuer & renames
- Loading branch information
Showing
7 changed files
with
85 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require 'faraday' | ||
require 'faraday_middleware' | ||
|
||
class Ditto::Client | ||
def get(path, params = {}) | ||
connection.get do |request| | ||
request.url "#{Ditto.base_path}/#{path}" | ||
request.headers['Content-Type'] = 'application/json' | ||
params.each { |key, val| request.params[key] = val } | ||
end.body | ||
end | ||
|
||
def put(path, params = {}) | ||
connection.put do |request| | ||
request.url "#{Ditto.base_path}/#{path}" | ||
request.headers['Content-Type'] = 'application/json' | ||
request.body = params.to_json | ||
end.body | ||
end | ||
|
||
def post(path, params = {}) | ||
connection.post do |request| | ||
request.url "#{Ditto.base_path}/#{path}" | ||
request.headers['Content-Type'] = 'application/json' | ||
request.body = params.to_json | ||
end.body | ||
end | ||
|
||
def connection | ||
@connection ||= Faraday.new(url: Ditto.base_url) do |c| | ||
c.adapter Faraday.default_adapter | ||
c.use Faraday::Response::RaiseError | ||
c.response :json, content_type: /\bjson$/ | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
require 'ditto/client' | ||
|
||
class Ditto::Issuer | ||
ATTRIBUTES = [:id, :name, :rfc, :regimen, :userNameSF, :passwordSF, :satPass, | ||
:production, :location, :fiscalLocation] | ||
attr_accessor(*ATTRIBUTES) | ||
|
||
def initialize(attrs = {}) | ||
attrs.each do |key, value| | ||
send("#{key}=", value) if respond_to? key | ||
end | ||
end | ||
|
||
def self.create(attrs = {}) | ||
new(attrs).save | ||
end | ||
|
||
def save | ||
if id.nil? | ||
client.post("/SaveEmisorMaster/Emisor?UserId=#{Ditto.api_key}", to_hash) | ||
end | ||
end | ||
|
||
private | ||
def client | ||
@client ||= Ditto::Client.new | ||
end | ||
|
||
def to_hash | ||
attrs = {} | ||
|
||
ATTRIBUTES.each do |a| | ||
value = send("#{a}") | ||
attrs[a] = value if !value.nil? | ||
end | ||
|
||
attrs | ||
end | ||
end |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
require 'ditto_ruby/version' | ||
require 'ditto_ruby/client' | ||
require 'ditto_ruby/emisor' | ||
require 'ditto/version' | ||
require 'ditto/issuer' | ||
|
||
module Ditto | ||
@api_key = 'benoror' | ||
@base_url = 'http://d9d5452e.ngrok.io' | ||
@base_path = '/Api/webresources/invoice' | ||
|
||
class << self | ||
attr_accessor :api_key, :base_url, :base_path | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.