Giter Club home page Giter Club logo

misoca_ruby_client's Introduction

MisocaRubyClient Build Status

Installation

Add this line to your application's Gemfile:

gem 'misoca_ruby_client'

And then execute:

$ bundle instal

Or install it yourself as:

$ gem install misoca_ruby_client

Usage

Because misoca's refresh token live quite a long time. You can save your token somewhere and constantly refresh the token(e.g. Cron) so you don't have to authorize everytime.

# Create a proc so that we can save the token to somewhere
update_config = proc { |access_token| 
	SomeModelToSaveToken.update_columns(misoca_access_token: access_token.token, misoca_refresh_token: access_token.refresh_token)
}

# Initialize client
mymisoca = MisocaRubyClient.new(application_id, secret, callback_url, update_config)

# Inject a saved token so that you can skip authentication
mymisoca.inject_access_token(misoca_access_token, misoca_refresh_token) if misoca_access_token && misoca_refresh_token

Then you can have a cron which do

mymisoca.refresh_access_token

at least once everyday.

You can also choose not using update_config. For this, you need a callback controller which do.

class OauthController < ApplicationController
  def misoca_authorization
    return redirect_to mymisoca.get_authorize_url
  end

  def misoca_callback
    mymisoca.exchange_token(params[:code])
    return redirect_to "/configs"
  end
end

Note that misoca_authorization redirect you to Misoca's oauth page. misoca_callback is the callback which receive params[:code] and update access token.

Create an invoice

invoice = {
  issue_date: Date.today,
  payment_due_on: Date.today,
  subject: "Pay Me Money",
  recipient_name: "You"
  recipient_title: 'Mr.',
  invoice_body_attributes: {
    recipient_zip_code: "123-4567",
    recipient_address1: "My Address",
    recipient_name1: "Someone",
    recipient_title: 'Chief',
  },
  invoice_items_attributes: [{
  	name: "work",
	quantity: 1,
	unit_price: 100,
  }]
}
mymisoca.access_token.post('/api/v1/invoice', { body: { invoice: invoice } })

misoca_ruby_client's People

Contributors

hokichaio avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

misoca_ruby_client's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.