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

Commit 816cc90

Browse files
committed
Implemented :get requests in Faraday and removed HTTParty dependency
1 parent 329df92 commit 816cc90

8 files changed

Lines changed: 29 additions & 66 deletions

File tree

buff.gemspec

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
1010
gem.email = ["[email protected]"]
1111
gem.description = %q{Buff is an API Wrapper Gem for Bufferapp.com's API}
1212
gem.summary = %q{Buff is an API Wrapper Gem for Bufferapp.com's API}
13-
gem.homepage = ""
13+
gem.homepage = "http://github.com/zph/buff"
1414

1515
gem.files = `git ls-files`.split($/)
1616
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -28,9 +28,8 @@ Gem::Specification.new do |gem|
2828

2929
gem.add_runtime_dependency 'multi_json'
3030
gem.add_runtime_dependency 'yajl-ruby'
31-
gem.add_runtime_dependency 'httparty'
32-
gem.add_runtime_dependency 'rash'
33-
gem.add_runtime_dependency 'addressable'
3431
gem.add_runtime_dependency 'faraday'
3532
gem.add_runtime_dependency 'faraday_middleware'
33+
gem.add_runtime_dependency 'rash'
34+
gem.add_runtime_dependency 'addressable'
3635
end

lib/buff.rb

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ class Client
5353

5454
attr_accessor :access_token, :auth_query
5555

56-
5756
def initialize(access_token)
5857
@access_token = access_token
5958
self.class.default_params :access_token => access_token
@@ -64,23 +63,13 @@ def initialize(access_token)
6463
end
6564

6665
def auth_query
67-
{ :query => {
68-
:access_token => @access_token
69-
}
70-
}
66+
{ :access_token => @access_token }
7167
end
7268

73-
base_uri "https://api.bufferapp.com/#{API_VERSION}"
74-
75-
76-
7769
def info
7870
response = get("/info/configuration.json")
7971
Buff::Info.new(response)
8072
end
81-
82-
8373
end
84-
8574
end
8675

lib/buff/core.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,21 @@ module Core
66
attr_reader :error_table
77

88
def get(path, options={})
9-
basic_request(path, :get, options)
10-
end
9+
options.merge!(auth_query)
10+
response = @conn.get do |req|
11+
req.url path.gsub(%r{^\/}, '')
12+
req.params = options
13+
end
1114

12-
def post(path, options={})
13-
basic_request(path, :post, options)
15+
interpret_response(response)
1416
end
1517

16-
def faraday_post(path="", post_data)
17-
path.gsub!(%r{^\/}, '')
18-
full_url = "#{path}?access_token=#{Buff::ACCESS_TOKEN}"
18+
def post(path, post_data)
1919
@conn.post do |req|
20-
req.url full_url
20+
req.url path.gsub(%r{^\/}, '')
2121
req.headers['Content-Type'] = "application/x-www-form-urlencoded"
2222
req.body = post_data
23+
req.params = auth_query
2324
end
2425
end
2526

@@ -29,15 +30,14 @@ def basic_request(path, verb, options={})
2930
end
3031

3132
def interpret_response(response)
32-
case response.code
33+
case response.status
3334
when 200
34-
response
35+
JSON.parse response.body
3536
else
3637
handle_response_code(response)
3738
end
3839
end
3940

40-
4141
def handle_response_code(response)
4242
error = Hashie::Mash.new( response.body )
4343
if ERROR_TABLE[error.code]

lib/buff/link.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module Buff
22
class Client
33
module Link
4-
def link(url)
5-
response = get("/links/shares.json?url=#{url}")
4+
def link(options)
5+
response = get("/links/shares.json", options)
66
Buff::Link.new(response)
77
end
88
end

lib/buff/profile.rb

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module Buff
22
class Client
33
module Profile
4-
# Profile API Calls
54
def profiles(options={})
65
response = get("/profiles.json", options)
76
response.map { |profile| Buff::Profile.new(profile) }
@@ -17,18 +16,13 @@ def profile_schedules_by_id(id, options={})
1716
response.map { |r| Buff::Schedule.new(r) }
1817
end
1918

20-
# Requires :schedules to be set
21-
# currently wipes out schedule on site
2219
# TODO massive bug
2320
# currently deletes schedule due to malformed request
2421
def set_schedules(id, options={})
2522
# schedules = options.fetch(:schedules) { raise ArgumentError }
26-
# options = { schedules: schedules }
27-
response = faraday_post("/profiles/#{id}/schedules/update.json", options )
23+
response = post("/profiles/#{id}/schedules/update.json", options )
2824
Buff::Response.new(JSON.parse(response.body))
2925
end
30-
3126
end
3227
end
33-
3428
end

lib/buff/update.rb

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,42 @@
11
module Buff
22
class Client
33
module Update
4-
5-
# Updates via Get
6-
# /updates/:id
7-
# /profiles/:id/updates/pending
8-
# /profiles/:id/updates/sent
9-
# /updates/:id/interactions
10-
#
114
def update_by_id(id, options={})
125
check_id(id)
136
response = get("/updates/#{id}.json")
147
Buff::Update.new(response)
158
end
169

17-
1810
def updates_by_profile_id(id, options={})
1911
optional_params = [ :page, :count, :since, :utc ]
2012
status = options.fetch(:status) do
2113
raise Buff::MissingStatus, "Include :pending or :sent in args"
2214
end
2315
options.delete(:status)
24-
response = get("/profiles/#{id}/updates/#{status.to_s}.json", {query: options} )
16+
response = get("/profiles/#{id}/updates/#{status.to_s}.json", options )
2517
updates = response['updates'].map { |r| Buff::Update.new(r) }
2618
Buff::Updates.new (
2719
{ total: response['total'], updates: updates } )
2820
end
2921

3022
def interactions_by_update_id(id, options={})
3123
optional_params = [:page, :count, :event]
32-
response = get("/updates/#{id}/interactions.json", {query: options})
24+
response = get("/updates/#{id}/interactions.json", options)
3325
interactions = response['interactions'].map { |r| Buff::Interaction.new(r) }
3426
Buff::Interactions.new(
3527
{ total: response['total'], interactions: interactions }
3628
)
3729
end
3830

39-
# Updates via post
40-
#POST
41-
# /profiles/:id/updates/reorder
42-
# /profiles/:id/updates/shuffle
43-
# /updates/create
44-
# /updates/:id/update
45-
# /updates/:id/share
46-
# /updates/:id/destroy
47-
4831
def reorder_updates(profile_id, options={})
4932
# order, optional: offset, utc
5033
order = options.fetch(:order) { raise ArgumentError }
51-
response = faraday_post("/profiles/#{profile_id}/updates/reorder.json", options)
34+
response = post("/profiles/#{profile_id}/updates/reorder.json", options)
5235
end
5336

5437
def shuffle_updates(profile_id, options={})
5538
# optional count, utc
56-
response = faraday_post("/profiles/#{profile_id}/updates/shuffle.json", options)
39+
response = post("/profiles/#{profile_id}/updates/shuffle.json", options)
5740
end
5841

5942
#TODO
@@ -73,23 +56,23 @@ def create_update(options={})
7356
# description: "That example page"
7457
# }
7558
# }
76-
response = faraday_post("/updates/create.json", options)
59+
response = post("/updates/create.json", options)
7760
Hashie::Mash.new(JSON.parse response.body)
7861
end
7962

8063
def modify_update_text(update_id, options={})
8164
# text, (now, media, utc)
8265
options.fetch(:text) { raise ArgumentError }
83-
response = faraday_post("/updates/#{update_id}/update.json", options)
66+
response = post("/updates/#{update_id}/update.json", options)
8467
Hashie::Mash.new(JSON.parse response.body)
8568
end
8669

8770
def share_update(update_id, options={})
88-
response = faraday_post("/updates/#{update_id}/share.json", options)
71+
response = post("/updates/#{update_id}/share.json", options)
8972
end
9073

9174
def destroy_update(update_id, options={})
92-
response = faraday_post("/updates/#{update_id}/destroy.json", options)
75+
response = post("/updates/#{update_id}/destroy.json", options)
9376
end
9477

9578
def check_id(id)

lib/buff/user.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
module Buff
22
class Client
33
module User
4-
54
def user_info(options={})
6-
response = get("/user.json")
7-
Buff::UserInfo.new(response)
5+
Buff::UserInfo.new(get("/user.json"))
86
end
97
end
108
end

spec/lib/buff/link_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
end
1212

1313
it "connects to the correct endpoint" do
14-
client.link(url)
14+
client.link({url: url})
1515
end
1616

1717
it "parses the shares of a link" do
18-
client.link(url).shares.should eq(47348)
18+
client.link({url: url}).shares.should eq(47348)
1919
end
2020

2121
end

0 commit comments

Comments
 (0)