This is a wrap of sindup.com API.
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
You have yet two different ways to instantiate your client.
t = Sindup::Authorization::Token.new "token", "refresh-token", Time.at(1437995506)
s = Sindup.new(app_id: "myAppId", app_secret: "myAppSecret", auth: { token: t })
# 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
More options are available for authorize_url
hash :
token_url
authorize_url
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>
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>
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.
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.
Each object correctly instantiated inherits the internal connection object that make them queryable.
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.
To push your modifications, just use the save
method.
fo.name = "newFolderName"
fo.save
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.
- Fork it ( https://github.com/Invoxis/sindup/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request