Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
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
95
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
「手軽で便利」に潜む罠。 Popover API を WCAG 2.2の視点で安全に使うには
taitotnk
0
630
ProxyによるWindow間RPC機構の構築
syumai
3
880
KessokuでDIでもgoroutineを活用する / Go Connect #6
mazrean
0
140
Testing Trophyは叫ばない
toms74209200
0
590
AIレビュアーをスケールさせるには / Scaling AI Reviewers
technuma
2
240
Go言語での実装を通して学ぶLLMファインチューニングの仕組み / fukuokago22-llm-peft
monochromegane
0
110
オープンセミナー2025@広島LT技術ブログを続けるには
satoshi256kbyte
0
150
Introducing ReActionView: A new ActionView-compatible ERB Engine @ Rails World 2025, Amsterdam
marcoroth
0
480
AIでLINEスタンプを作ってみた
eycjur
1
220
print("Hello, World")
eddie
1
460
Claude Codeで挑むOSSコントリビュート
eycjur
0
190
The state patternの実践 個人開発で培ったpractice集
miyanokomiya
0
160
Featured
See All Featured
Designing for Performance
lara
610
69k
Docker and Python
trallard
45
3.5k
The Art of Programming - Codeland 2020
erikaheidi
55
13k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
61k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Facilitating Awesome Meetings
lara
55
6.5k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
53k
Intergalactic Javascript Robots from Outer Space
tanoku
272
27k
Fireside Chat
paigeccino
39
3.6k
Building Applications with DynamoDB
mza
96
6.6k
How STYLIGHT went responsive
nonsquared
100
5.8k
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?