Giter VIP home page Giter VIP logo

ruby-egnyte's Introduction

Ruby Egnyte

This SDK is no longer supported by Egnyte. It continues to be available as-is and pull requests will be merged, but no support will be provided.

A feature-rich Ruby client for the Egnyte API.

Special thanks to the folks at Attachments.me and Yesware, Inc. who got this library off to a great start.

Build Status

Authentication

  • Create a session object with your Egnyte API Key
  • Create an authorize url and direct a user to it, to retrieve an access_token for their account.
require 'egnyte'

session = Egnyte::Session.new({
    key: 'api_key',
    domain: 'egnyte_domain'
})
session.authorize_url('https://127.0.0.1/oauth2callback')

# direct the user to the authorize URL generated,
# the callback provided will be executed with an access token.

session.create_access_token('the_access_token_returned')
  • Create a client, with the authenticated session.
@client = Egnyte::Client.new(session)

The client initialized, we can start interacting with the Egnyte API.

Folders

  • Fetching a folder
folder = @client.folder('/Shared')
p folder.name # outputs 'Shared'.
  • Listing files in a folder.
@client.folder('/Shared/Documents/').files.each {|f| p f.name}
# outputs "IMG_0440.JPG", "IMG_0431.JPG"
  • Creating a folder.
new_folder = @client.folder('/Shared/Documents/').create('banana')
p new_folder.path # a new folder was created /Shared/Documents/banana
  • Deleting a folder.
folder = @client.folder('/Shared/Documents/banana')
folder.delete

Files

  • Fetching a file
file = @client.file('/Shared/example.txt')
p file.name # example.txt.
  • Deleting a file.
@client.file('/Shared/example.txt').delete
  • Uploading a file.
local_path = "./LICENSE.txt"
filename = "LICENSE.txt"

folder = @client.folder('Shared/Documents/')
File.open( local_path ) do |data|
 folder.upload(filename, data)
end
  • Downloading a file.
file = @client.file('/Shared/Documents/LICENSE.txt')
file.download

Rate limitations

There are rate limitations on a per-token basis in the Egnyte API: per second, and daily quota.

The library raises a Egnyte::RateLimitExceededPerSecond when you go over your alloted rate per second, and raises a Egnyte::RateLimitExceededQuota when you go over your alloted daily quota. Both exceptions contain a retry_after value.

You can also instantiate the session with the optional keyword variable retries: 5 e.g.:

session = Egnyte::Session.new(
           {access_token: 'secret-token', domain: 'egnyte_domain', username: 'me'}, 
           :implicit, # or :password for internal apps 
           0.0, # backoff of 0 makes sense if you are retrying 
           retries: 5)

Contributing

  1. Fork it
  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 new Pull Request

ruby-egnyte's People

Contributors

naugtur avatar pfeffed avatar timdiggins avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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.