Giter Club home page Giter Club logo

agx-ruby's Introduction

agX Platform API Client

Gem Version

Ruby client for accessing SST Software's agX Platform APIs.

Installation

Add this line to your application's Gemfile:

gem 'agx'

And then execute:

$ bundle

Or install it yourself as:

$ gem install agx

Usage

agX Content API

Setup agX Content Client (OAuth 2 Client Credentials Flow)

@agx_content_client = Agx::Content::Client.new(
  client_id: "your_client_id",
  client_secret: "your_client_secret",
  version: "v1"  # optional
  prod: true # optional, false for QA
)

Make get requests for Content API resources

# @agx_content_client.get("ResourceName", params_hash)
# => 'parsed_json_response_body'

crops = @agx_content_client.get("Crop")

# Passing in publishDate as param
weeds = @agx_content_client.get("Weed", {publishDate: date.to_s})

agX Sync API

Setup agX Sync Client (OAuth 2 Authorization Code Flow)

This requires that you have already previously authenticated and authorized a user to agX through the authorization code grant flow process and have persisted their sync ID, access token, refresh token, and access token expiration timestamp.

@agx_sync_client = Agx::Sync::Client.new(
  client_id: "your_client_id",
  client_secret: "your_client_secret",
  version: "v3",  # optional
  sync_id: "agx_user_sync_id",
  access_token: "agx_user_agx_token",
  refresh_token: "agx_user_refresh_token",
  token_expires_at: "access_token_expiration_timestamp",
  transaction_id: "agx_user_previous_transaction_id" # optional,
  prod: true # optional, false for QA
)

Initiate a sync transaction, make Sync API requests, and end transaction

Currently only get requests are supported

# @agx_sync_client.get("Resource", start_time)
# => 'parsed_json_response_body'

# You should persist transaction ID per user until transaction is successfully
# ended by call to end_transaction
transaction_id = @agx_sync_client.start_transaction

growers = @agx_sync_client.get("Grower")

# Get all farms accessible for a grower
farms = @agx_sync_client.get("Grower/#{grower.guid}/Farm")

# Get all server changes on farms accessible for a grower since start_time
farms = @agx_sync_client.get("Grower/#{grower.guid}/Farm", last_sync_date.to_s)

# etc...

@agx_sync_client.end_transaction

# clear the persisted transaction ID for user after ending sync transaction
user_transaction_id = nil

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment. To install this gem onto your local machine, run bundle exec rake install.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/brycejohnston/agx-ruby.

License

The gem is available as open source under the terms of the MIT License (see LICENSE.txt)

agX is a registered trademark of SST Software.

agx-ruby's People

Contributors

brycejohnston avatar

Watchers

James Cloos avatar Thiago Osses  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.