weekly learning

Posted by ilake on August 7, 2016

“strive 7/31 ~ 8/6”


  • [Gem] vcr

    1. For test, it could record real third party response to yml file
    2. Use it with webmock’s body
  • [Gem] webmock

  • [Gem] rubocop

    1. rubocop –auto-correct
  • [Gem] webmock

    1. If you use multiple sidekiq processes then you can specify limits per process
  • [Gem] figaro

    1. Figaro was written to make it easy to securely configure Rails applications.
  • [Gem] docker-api

  • [Gem] active_type

    1. ActiveType is our take on “presenter models” (or “form models”) in Rails. We want to have controllers (and forms) talk to models that are either not backed by a database table
  • [Gem] png_quantizator

    1. PngQuantizator is a little wrapper around pngquant



Work design

  • API Architecture

  • Design

    1. client auth: follow aws, use current timestamp + private key as checksum, server need to verify checksum, also need to make sure timestamp in some duration (like 10 mins)
    2. user auth: logined user will have one or more token. use token as key, value is user id, and set expired time on every token, save them on redis, so when client send token, server could know the current user.
    3. error handler:
      • one config, record key, status code of error, error message use key for i18n.
      • every api action has its service object, when render api error will raise specific exception class and error key,this exception will rescue from base controller, and according error key to error render. All the data format will be the same, the different are message, key, status code

– learned from MarsZ

  • Implement

    1. controller only handle flow, other through service.
    2. use value object to handle user session, due to operation very like model CRUD, so use value, and base is redis hash
    3. exception only on controller raise, service use active model save error message, when return false, we could get error message from service and raise with exception class
  • ** Learn **

    1. feature driven coding
      • every commit with small main part of the feature
    2. service with callback
    3. exceptio class
    4. every concerns only focus one thing
    5. RSpec from base stack
    6. how to use service to architecture base of whole application