When working with API clients there are several distinct areas of concern. Each of these happen in sequence and are used with the goal of receiving a Domain Model at the end.
This is still in rough draft form. I will continue to make edits as I receive them. I will collate the list of feedback here and make notes of the changelog as revisions are made.
No string interpolation for building your routes to your resources.
Here are the concerns:
- Routes: How do I get to the necessary resource?
- Configuration: What options do I want for my connection or requests
- Connection: How do I connect to the application? Typically this will be HTTP(S).
- Logging: We will have specific logging for the api, the requests, and applications.
- Errors: We will have specific exceptions we raise if any issues arise.
- Requests: These use the routes and connections to make a request to the service. The return from this is a response.
- Response: The response from a request is typically a schema that aligns with content negotiation (
Content-Type
orAccept
)
I hereby claim:
- I am nateklaiber on github.
- I am nateklaiber (https://keybase.io/nateklaiber) on keybase.
- I have a public key whose fingerprint is 6930 A573 358D 135A 2269 F9CC 7B5D D6D8 F811 B831
To claim this, I am signing this object:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NameFormat | |
attr_reader :first_name, :last_name, :middle_name | |
def initialize(person) | |
@person = person | |
@first_name = person.first_name | |
@last_name = person.last_name | |
@middle_name = person.middle_name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FlatArray | |
instance_methods.each do |m| | |
undef_method(m) unless m =~ /(^__|^nil\?|^send$|^object_id$)/ | |
end | |
def initialize(array) | |
@target = array | |
end | |
def respond_to?(symbol, include_priv=false) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
t = 236 # seconds | |
Time.at(t).utc.strftime("%H:%M:%S") | |
=> "00:03:56" | |
# Reference | |
# http://stackoverflow.com/questions/3963930/ruby-rails-how-to-convert-seconds-to-time |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cat *.json |\ | |
jq 'map(select(.from.name=="Nate Klaiber"))' |\ | |
jq '.[].message' |\ | |
grep -v 'jq' |\ | |
sed -e 's/\([[:punct:]]\)//g' |\ | |
grep -v '^$' |\ | |
tr '\n' ' ' |\ | |
tr ' ' '\n' |\ | |
tr '[:upper:]' '[:lower:]' |\ | |
sort |\ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
API_HOST='http://utilities.theklaibers.com' | |
CACHE_HOST='localhost:11211' |
I'll use Stripe as an example. The client is responsible for:
- Configuration
- Routing
- Connection Handling
- Request Handling
- Raw requests with JSON
- Object model requests that wrap the raw request (allow us to say
Stripe::Request::Charge.get(id: 'sdfsdf')
)
- Object Creation. This includes top level and associations.
NewerOlder