Skip to content
This repository was archived by the owner on Mar 5, 2026. It is now read-only.

Commit bd6ff46

Browse files
committed
Initial Commit
0 parents  commit bd6ff46

15 files changed

Lines changed: 415 additions & 0 deletions

File tree

.gitignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
*.gem
2+
*.rbc
3+
.bundle
4+
.config
5+
.yardoc
6+
Gemfile.lock
7+
InstalledFiles
8+
_yardoc
9+
coverage
10+
doc/
11+
lib/bundler/man
12+
pkg
13+
rdoc
14+
spec/reports
15+
test/tmp
16+
test/version_tmp
17+
tmp

Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
source 'https://rubygems.org'
2+
3+
# Specify your gem's dependencies in buff.gemspec
4+
gemspec

Guardfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# A sample Guardfile
2+
# More info at https://github.com/guard/guard#readme
3+
4+
guard :rspec do
5+
watch(%r{^spec/.+_spec\.rb$})
6+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
7+
watch('spec/spec_helper.rb') { "spec" }
8+
9+
end
10+

LICENSE.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Copyright (c) 2013 ZPH
2+
3+
MIT License
4+
5+
Permission is hereby granted, free of charge, to any person obtaining
6+
a copy of this software and associated documentation files (the
7+
"Software"), to deal in the Software without restriction, including
8+
without limitation the rights to use, copy, modify, merge, publish,
9+
distribute, sublicense, and/or sell copies of the Software, and to
10+
permit persons to whom the Software is furnished to do so, subject to
11+
the following conditions:
12+
13+
The above copyright notice and this permission notice shall be
14+
included in all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Buff
2+
3+
Buff is a Buffer API Wrapper written in Ruby. It attempts to provide more thorough API coverage than the existing gem.
4+
5+
Since the gem is currently in ALPHA development, the interface is prone to change. Please wait until v0.1.0 is released to become reliant on interface.
6+
7+
## Installation
8+
9+
Once Buff is released as a gem, the following instructions will work. For now please `git clone` the repo.
10+
11+
Add this line to your application's Gemfile:
12+
13+
gem 'buff'
14+
15+
And then execute:
16+
17+
$ bundle
18+
19+
Or install it yourself as:
20+
21+
$ gem install buff
22+
23+
## Usage
24+
25+
Use it and note which API coverage exists.
26+
27+
## API Coverage
28+
29+
Implemented
30+
==
31+
User
32+
Profiles (:get)
33+
Updates (:get)
34+
35+
Not Implemented
36+
==
37+
Authentication (Try OAuth-buffer)
38+
Profiles (:post)
39+
Updates (:post & optional params)
40+
Links
41+
Info
42+
Error Codes
43+
Optional params for get requests
44+
45+
## Contributing
46+
47+
1. Fork it
48+
2. Create your feature branch (`git checkout -b my-new-feature`)
49+
3. Commit your changes (`git commit -am 'Add some feature'`)
50+
4. Push to the branch (`git push origin my-new-feature`)
51+
5. Create new Pull Request
52+
53+
Issues, advice and refactoring is welcome.
54+
55+
Also, this project is newcomer friendly!! We'd love to be your first Open Source Software contribution and would be happy to assist in that process.
56+
57+
Reach out on Twitter [@_ZPH](http://twitter.com/_ZPH).

Rakefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require "bundler/gem_tasks"
2+
require 'rake'
3+
4+
task :curl_dump, [ :url ] do |t, args|
5+
access_token = `cat ~/.bufferapprc | head -3 | tail -1`.chomp
6+
sh "curl -is #{args[:url]}?access_token=#{access_token}"
7+
end

buff.gemspec

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# -*- encoding: utf-8 -*-
2+
lib = File.expand_path('../lib', __FILE__)
3+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4+
require 'buff/version'
5+
6+
Gem::Specification.new do |gem|
7+
gem.name = "buff"
8+
gem.version = Buff::VERSION
9+
gem.authors = ["ZPH"]
10+
gem.email = ["[email protected]"]
11+
gem.description = %q{TODO: Write a gem description}
12+
gem.summary = %q{TODO: Write a gem summary}
13+
gem.homepage = ""
14+
15+
gem.files = `git ls-files`.split($/)
16+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18+
gem.require_paths = ["lib"]
19+
20+
gem.add_development_dependency 'rspec'
21+
gem.add_development_dependency 'webmock'
22+
gem.add_development_dependency 'guard-rspec'
23+
gem.add_development_dependency 'guard-bundler'
24+
gem.add_development_dependency 'rb-fsevent'
25+
gem.add_development_dependency 'growl'
26+
gem.add_development_dependency 'pry-full'
27+
gem.add_development_dependency 'rake'
28+
29+
gem.add_runtime_dependency 'multi_json'
30+
gem.add_runtime_dependency 'yajl-ruby'
31+
# gem.add_runtime_dependency 'faraday_middleware'
32+
gem.add_runtime_dependency 'httparty'
33+
gem.add_runtime_dependency 'rash'
34+
end

lib/buff.rb

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
require "httparty"
2+
require "json"
3+
require "rash"
4+
5+
require "buff/version"
6+
require "buff/core"
7+
require "buff/user"
8+
require "buff/profile"
9+
require "buff/update"
10+
11+
module Buff
12+
13+
class UserInfo < Hashie::Mash; end
14+
class Profile < Hashie::Mash; end
15+
class Response < Hashie::Mash; end
16+
class Update < Hashie::Mash; end
17+
class Updates < Hashie::Mash; end
18+
class Interaction < Hashie::Mash; end
19+
class Interactions < Hashie::Mash; end
20+
21+
class Schedule < Hashie::Mash; end
22+
Schedules = Class.new(Array) do
23+
def dump
24+
{ schedules: self }.to_json
25+
end
26+
end
27+
28+
InvalidIdLength = Class.new(ArgumentError)
29+
InvalidIdContent = Class.new(ArgumentError)
30+
MissingStatus = Class.new(ArgumentError)
31+
32+
class Client
33+
include HTTParty
34+
include Core
35+
include User
36+
include Profile
37+
include Update
38+
39+
attr_accessor :access_token, :auth_query
40+
41+
base_uri "https://api.bufferapp.com/#{API_VERSION}"
42+
43+
def initialize(access_token)
44+
@access_token = access_token
45+
@auth_query = {
46+
:query => {
47+
'access_token' => access_token
48+
}
49+
}
50+
end
51+
end
52+
end
53+

lib/buff/core.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module Buff
2+
class Client
3+
module Core
4+
API_VERSION = "1"
5+
6+
def get(path, options=auth_query)
7+
self.class.get(path, options)
8+
end
9+
end
10+
end
11+
end

lib/buff/profile.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
module Buff
2+
class Client
3+
module Profile
4+
# Profile API Calls
5+
def profiles(options={})
6+
response = get("/profiles.json")
7+
response.map { |profile| Buff::Profile.new(profile) }
8+
end
9+
10+
def profile_by_id(id, options={})
11+
response = get("/profiles/#{id}.json")
12+
Buff::Profile.new(response)
13+
end
14+
15+
def profile_schedules_by_id(id, options={})
16+
response = get("/profiles/#{id}/schedules.json")
17+
response.map { |r| Buff::Schedule.new(r) }
18+
end
19+
20+
# Requires :schedules to be set
21+
def set_schedules(id, options={})
22+
schedules = options.fetch(:schedules) { raise ArgumentError }
23+
#process schedules object
24+
# permit it to be hash or Buff::Schedules
25+
# TODO left off here 20130515 10pm
26+
27+
response = post("/profiles/#{id}/schedules/update.json")
28+
Buff::Response.new(response)
29+
end
30+
31+
end
32+
end
33+
34+
end

0 commit comments

Comments
 (0)