Giter VIP home page Giter VIP logo

sindup's Introduction

Sindup

This is a wrap of sindup.com API.

Installation

Add this line to your application's Gemfile:

gem 'sindup', github: 'Invoxis/sindup'

And then execute:

$ bundle

Or install it yourself as:

$ gem install sindup

Usage

Instantiate the client.

You have yet two different ways to instantiate your client.

If you got a valid token/refresh-token pair.

t = Sindup::Authorization::Token.new "token", "refresh-token", Time.at(1437995506)
s = Sindup.new(app_id: "myAppId", app_secret: "myAppSecret", auth: { token: t })

If you know your user ids

# Your code :
options = {
	app_id: "myAppId", app_secret: "myAppSecret",
	auth: { basic: "myEmail:myPassword" },
	authorize_url: { redirect_url: "http://example.com/sindup/callback" }
}
s = Sindup.new(options)

# Your sindup controller :
  def callback
    render json: Sindup.received_authorization_callback(params)
  end

Note

More options are available for authorize_url hash :

  • token_url
  • authorize_url

Retrieve your current token

If you prefer to save in your database a token instead of your ids, you could retrieve your token using

s.current_token
 => #<Sindup::Authorization::Token:0x00000003749138 @token="myToken", @refresh_token="myRefreshToken", @expires_at=2015-07-27 13:11:46 +0200>

Collections

All different objects are associated to collections.

Your client could have several folders. Your client can access to its neighbor users. A folder could have several collect filters and results.

s.users
 => #<Sindup::Collection::User:0x0000000369ea80>
s.folders
 => #<Sindup::Collection::Folder:0x000000036a2658>

Laziness

All collections are "lazy". Their data is not loaded until you ask for. You can't retrieve all objects by once. You can only iterate over each of them using each.

s.folders.each { |folder|  }
 => {:cursor=>nil, :total_queries=>1, :total_markers=>0, :total_initialized_items=>15, :total_different_initialized_items=>15, :total_matching_initialized_items=>15} 

Instead, you get statistics on what you have iterated.

Criterias

You can specify criterias to select items matching your needs. Just use the where function on your collection. Note that you have to give the function Procs

s.folders.where(->(fo) { fo.name.include?("test") })
 => #<Sindup::Collection::Folder:0x000000027f8be8>

In case you don't want to iterate on results you have already seen, you can specify an endpoint. It could be the id of the last item you know...

s.folders.until(42)
 => #<Sindup::Collection::Folder:0x00000002739108>

... or a condition :

s.folders.until(->(fo) { fo.id <= 42 })
 => #<Sindup::Collection::Folder:0x00000002739108>

Unlike criterias, you can't chain end-criterias. Only the last provided is used.

Models

Each object correctly instantiated inherits the internal connection object that make them queryable.

Instantiating

You can instantiate an object from its dedicated collection.

fo = s.folders.new(folder_id: 42, name: "folderName", description: "folderDescription")

Your object will only be able to deal with its collections if you instantiate it with an id.

Updating

To push your modifications, just use the save method.

fo.name = "newFolderName"
fo.save

Creation

You can either use the create method on a collection...

fo = s.folders.create(name: "folderName")

... or save an object that don't have any primary key set :

fo = s.folders.new(name: "folderName")
fo = fo.save

To create a user, you will need

  • the correct access rights
  • to provide your client_id when instantiating your client.

Contributing

  1. Fork it ( https://github.com/Invoxis/sindup/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

sindup's People

Contributors

etrnljg avatar jgburet avatar

Watchers

 avatar  avatar

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.