Giter Site home page Giter Site logo

teamweek-ruby's Introduction

A very lightweight ruby library without an http client to communicate with Teamweek API

Gem Version

Why clientless?

When integrating with more than one remote API (e.g. Teamweek and Basecamp) you can share one http client class between the multiple API clients, which enables unified error and access handling.

HTTP Client

The HTTP client is responsible for authorization, user agent and HTTP caching headers and whatever else you need. The HTTP client that is passed to the Teamweek::Api::Client must implement the following methods, that this gem uses:

  • post(full_path, data) - HTTP POST request, which gets the full request uri and request body data as hash and returns the response body as JSON

Example usage

  require 'teamweek-ruby'
  require 'httparty'

  class CustomHttpClient
    attr_accessor :headers

    def initialize(access_token)
      @headers = { "Authorization" => "Bearer #{access_token}", "User-Agent"  => "Teamweek Ruby" }
    end

    #method required by teamweek-ruby
    def post(path, params)
      #response and error handling can be done here
      HTTParty.post(path, { headers: headers, body: params })
    end

  end

  workspace_id = 123
  access_token = 'some_users_access_token'

  http_client = CustomHttpClient.new(access_token)
  teamweek_ruby = Teamweek::Api::Client.new(http_client, workspace_id)
  projects = teamweek_ruby.import_projects([{name:"My Project"}, {name: "Another project"}])

Building and using the gem

If you want to test your changes, build and install the gem in your machine (see more at http://guides.rubygems.org/make-your-own-gem/).

% gem build teamweek-ruby.gemspec

  Successfully built RubyGem
  Name: teamweek-ruby
  Version: 0.1.0
  File: teamweek-ruby-0.1.0.gem

% gem install teamweek-ruby-0.1.0.gem
% irb
>> require 'teamweek-ruby'
=> true

teamweek-ruby's People

Contributors

janika avatar

Stargazers

Lucas Ocon avatar

Watchers

Marek Tihkan avatar Serge avatar James Cloos avatar  avatar Marit 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.