Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Building API clients with Cistern
Search
Adam Holt
February 20, 2014
Programming
0
97
Building API clients with Cistern
@nwrug - github.com/lanej/cistern
Adam Holt
February 20, 2014
Tweet
Share
More Decks by Adam Holt
See All by Adam Holt
NWRUG - Celluloid
omgitsads
3
240
Other Decks in Programming
See All in Programming
MAP, Jigsaw, Code Golf 振り返り会 by 関東Kaggler会|Jigsaw 15th Solution
hasibirok0
0
190
AIコードレビューがチームの"文脈"を 読めるようになるまで
marutaku
0
250
Combinatorial Interview Problems with Backtracking Solutions - From Imperative Procedural Programming to Declarative Functional Programming - Part 1
philipschwarz
PRO
0
120
TypeScript 5.9 で使えるようになった import defer でパフォーマンス最適化を実現する
bicstone
1
590
競馬で学ぶ機械学習の基本と実践 / Machine Learning with Horse Racing
shoheimitani
14
14k
【レイトレ合宿11】kagayaki_v4
runningoutrate
0
200
モデル駆動設計をやってみよう Modeling Forum2025ワークショップ/Let’s Try Model-Driven Design
haru860
0
210
Level up your Gemini CLI - D&D Style!
palladius
1
150
251126 TestState APIってなんだっけ?Step Functionsテストどう変わる?
east_takumi
0
290
俺流レスポンシブコーディング 2025
tak_dcxi
9
6k
React Native New Architecture 移行実践報告
taminif
1
120
FluorTracer / RayTracingCamp11
kugimasa
0
150
Featured
See All Featured
Raft: Consensus for Rubyists
vanstee
140
7.2k
Six Lessons from altMBA
skipperchong
29
4.1k
Side Projects
sachag
455
43k
GraphQLとの向き合い方2022年版
quramy
49
14k
Making the Leap to Tech Lead
cromwellryan
135
9.6k
How to train your dragon (web standard)
notwaldorf
97
6.4k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
285
14k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
61k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
132
19k
Embracing the Ebb and Flow
colly
88
4.9k
Optimising Largest Contentful Paint
csswizardry
37
3.5k
Transcript
BUILDING API CLIENTS WITH CISTERN
@adamholt
@lanejoshlane
WHAT IS CISTERN?
“Cistern helps you consistently build your API clients and facilitates
building mock support.”
None
SERVICE
class Twitter::Client < Cistern::Service ! model_path "twitter/models" request_path "twitter/requests" !
model :tweet collection :tweets request :create_tweet ! class Real def initialize(options={}) # Setup end end ! class Mock def self.data; @data ||= {}; end ! def initialize(options={}) # Setup Mock Data end end end
class Twitter::Client < Cistern::Service model_path "twitter/models" request_path "twitter/requests" ! ...
end
class Twitter::Client < Cistern::Service ... ! model :tweet collection :tweets
request :create_tweet ! ... end
class Twitter::Client < Cistern::Service ... ! class Real def initialize(options={})
# Setup end end ! class Mock def self.data; @data ||= {}; end ! def initialize(options={}) # Setup Mock Data end end end
MODELS
class Twitter::Client::Tweet < Cistern::Model identity :id ! attribute :user, type:
:hash attribute :tweet, type: :array ! def retweet requires :id ! new_attributes = connection.retweet_tweet(id: id).body merge_attributes(new_attributes) end end !
COLLECTIONS
class Twitter::Client::Tweets < Cistern::Collection ! model Twitter::Client::Tweet ! def timeline(params
= {}) response = connection.get_tweets(params) ! data = self.clone.load(response.body) ! collection.attributes.clear collection.merge_attributes(data) end ! def retweets(params={}) response = connection.get_retweets(params) ... end ! def get(id) new(connection.get_tweet("id" => id).body) end end
REQUESTS
module Twitter class Client class Real def create_tweet(options={}) request( :body
=> {status: options[:body]}, :method => :post, :path => '/statuses/update' ) end end # Real ! ... end # Client end # Twitter
module Twitter class Client ... ! class Mock def create_tweet(options={})
id = Foo.random_hex(6) ! tweet = { "id" => id, "text" => "Hello from @NWRUG", "user" => {"name": "omgitsads"}, }.merge(options) ! self.data[:tweets][id]= tweet ! response( :body => tweet, :status => 200, :path => '/statuses/user_timeline.json', ) end end # Mock end # Client end # Twitter
DRAWBACKS
QUESTIONS?