Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add user setup endpoint #4

Merged
merged 5 commits into from
Jan 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,22 @@ Certificate methods:
certificate.delete
```

User methods

- Setup Widget

```ruby
args = {
email: 'some@email.com',
tax_id: 'AAA010101AAA',
callback_url: 'http://some-callback.url'
}

user = Mifiel::User.setup_widget(args)
user.widget_id
```


## Contributing

1. Fork it ( https://github.com/[my-github-username]/mifiel/fork )
Expand Down
1 change: 1 addition & 0 deletions lib/mifiel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module Mifiel
autoload :Certificate, 'mifiel/certificate'
autoload :Template, 'mifiel/template'
autoload :Config, 'mifiel/config'
autoload :User, 'mifiel/user'

BASE_URL = 'https://www.mifiel.com/api/v1'.freeze

Expand Down
27 changes: 27 additions & 0 deletions lib/mifiel/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module Mifiel
class User < Mifiel::Base
post :setup_widget, '/users/setup-widget'

# rubocop:disable Metrics/MethodLength, Metrics/AbcSize
def self.setup_widget(args)
email = args[:email]
tax_id = args[:tax_id]
callback_url = args[:callback_url]

raise ArgumentError, 'Email must be provided' unless email
raise ArgumentError, 'Tax id must be provided' unless tax_id
rest_request = RestClient::Request.new(
url: "#{Mifiel.config.base_url}/users/setup-widget",
method: :post,
payload: {
email: email,
tax_id: tax_id,
callback_url: callback_url
},
ssl_version: 'SSLv23'
)
req = ApiAuth.sign!(rest_request, Mifiel.config.app_id, Mifiel.config.app_secret)
Mifiel::User.new(JSON.parse(req.execute))
end
end
end
18 changes: 9 additions & 9 deletions mifiel.gemspec
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

require 'mifiel/version'

# rubocop:disable Metrics/BlockLength
# rubocop:disable Metrics/BlockLength, Layout/ExtraSpacing
Gem::Specification.new do |spec|
spec.name = 'mifiel'
spec.version = Mifiel::VERSION
Expand All @@ -19,9 +19,9 @@ Gem::Specification.new do |spec|
spec.require_paths = ['lib']
spec.required_ruby_version = '~> 2.1'

spec.add_runtime_dependency 'rest-client', '>= 1.8'
spec.add_runtime_dependency 'json', '~> 1.8'
spec.add_runtime_dependency 'api-auth', '~> 1.4'
spec.add_runtime_dependency 'json', '~> 1.8'
spec.add_runtime_dependency 'rest-client', '>= 1.8'
# Use Gem::Version to parse the Ruby version for reliable comparison
# ActiveSupport 5+ requires Ruby 2.2.2
if Gem::Version.new(RUBY_VERSION) > Gem::Version.new('2.2.2')
Expand All @@ -31,14 +31,14 @@ Gem::Specification.new do |spec|
end
spec.add_runtime_dependency 'flexirest', '~> 1.3.35'

spec.add_development_dependency 'bump', '~> 0.5', '>= 0.5.3'
spec.add_development_dependency 'bundler', '~> 1.6'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'rspec', '~> 3.1', '>= 3.1.7'
spec.add_development_dependency 'byebug', '~> 9.0', '< 9.0.6'
spec.add_development_dependency 'pry-byebug', '~> 3.4', '>= 3.3.0'
spec.add_development_dependency 'bump', '~> 0.5', '>= 0.5.3'
spec.add_development_dependency 'webmock', '~> 1.22', '>= 1.22.2'
spec.add_development_dependency 'sinatra', '~> 1.4', '>= 1.4.7'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'rspec', '~> 3.1', '>= 3.1.7'
spec.add_development_dependency 'rubocop', '0.47.1'
spec.add_development_dependency 'simplecov', '~> 0.15'
spec.add_development_dependency 'sinatra', '~> 1.4', '>= 1.4.7'
spec.add_development_dependency 'webmock', '~> 1.22', '>= 1.22.2'
end
14 changes: 14 additions & 0 deletions spec/mifiel/user_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
describe Mifiel::User do
describe '#setup_widget' do
let(:user) do
Mifiel::User.setup_widget(
email: 'user@email.com',
tax_id: 'AAA010101AAA',
callback_url: 'http://some-callback.url/mifiel'
)
end

it { expect(user.success).to be_truthy }
it { expect(user.widget_id).to_not be_nil }
end
end
6 changes: 6 additions & 0 deletions spec/support/fake_mifiel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ class FakeMifiel < Sinatra::Base
{ bla: 'Correo enviado' }.to_json
end

post '/api/v1/users/setup-widget' do
content_type :json
status 200
{ widget_id: '123bc', success: true }.to_json
end

private

def template(args = {})
Expand Down