-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathsection_10.html
More file actions
71 lines (58 loc) · 6.88 KB
/
Copy pathsection_10.html
File metadata and controls
71 lines (58 loc) · 6.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title></title>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>
<div class="chapter">
<h2 id='command_line_shopify'>Command Line Shopify</h2>
<p>Development of Apps requires being able to fire off requests to a shop and to be able to process the responses. WebHooks are a source of incoming data from a Shop but there are many interesting possibilities available using a console terminal to access the API at the command line.</p>
<p>Firing off a request for a resource to a Shop uses JSON or XML and it occurs with a standard HTTP verb like GET. To send a GET request to a shop with authentication is an involved process using the command line. A curl command to send of a request to a Shop for a product or collection resource is somewhat complex. Who memorizes curl commands? It is tedious. There are better ways to do this.</p>
<p>Shopify has a super application they bundle with their Ruby gem for the Shopify API. Before Rails merged with Merb, the Merbists advanced the concept of command-line interface (CLI) development for Ruby with the introduction of Thor. Thor is Ruby code that generates command-line interfaces and is a nice replacement for rake tasks. The new command is simple <em>shopify</em>.</p>
<p>Start a terminal session on your computer and you will be able to test this command out. You do know the console and you do want to have the Ruby scripting language and the shopify api gem installed.</p>
<div class='figure'>
<img alt='Available Options for the shopify Command Line Interface' src='../images/CLI2.png' />
</div>
<h3 id='the_shopify_command_line_console'>The shopify Command Line Console</h3>
<p>There are just a few options listed and in order to really cook up some interesting examples use the configure option that comes with the command. The arguments required to configure a shopify session are the shop’s API key and a password. To get those values, use the shop itself. For some developers this will mean using their development shop, and for others, their clients have provided access to their shop so a private App can be created, or they created the Private App for the developer and passed on the credentials. The following screen shots show the exact sequence.</p>
<div class='figure'>
<img alt='Menu Options to Setup Shop Access for the Command Line' src='../images/Manage%20Apps2.png' />
</div><div class='figure'>
<img alt='Setting Up Access for a Private Application' src='../images/Private%20Application2.png' />
</div><div class='figure'>
<img alt='Final Step Reveals the Needed Access Credentials' src='../images/Private%20App.png' />
</div>
<p>When examining the credentials provided for a Private App Tool, use the API key and password along with the shop name. Once the configuration is completed access the shop using a console is easy.</p>
<p>The following figure is a console session for a development shop showing a query for the shop’s count of products, orders, and the details of a single order.</p>
<div class='figure'>
<img alt='Output of Calling a Shop Using the API' src='../images/shopify_console.png' />
</div>
<p>Testing out potential code snippets quickly without incurring a lot of overhead is a huge benefit. API code can be tested with the fewest possible keystrokes and minimum effort with this handy console. It is possible to access metafield resources by providing an ID for the resource. The syntax of a call with Active Resource can be a challenge to keep in your head. With the console it’s possible to try command syntax out to see what the exact response is. With the console it is easier to try a few different call patterns until stumbling on the desired one.</p>
<p>You can add connections to as many shops as needed and you can list them all. When working on a client shop one of the first things to do is to use the shop admin interface and the App tab to create a private tool. The console is super useful to quickly test out any custom queries to build into an App for the merchant.</p>
<h3 id='the_shopify_theme_command_line_console'>The Shopify Theme Command Line Console</h3>
<p>A second useful command line tool that Shopify provides is not in the shopify_api gem but is a separate gem called shopify_theme. With this gem installed on a system you can use the command <strong>theme</strong> to develop the shop theme. Theme offers a simple workflow. The first thing to do with a shop development project is to create a directory to hold all the files that make up the merchant’s theme.</p>
<div class='highlight'><pre>$ mkdir fizz-buzz.com
$ cd fizz-buzz.com
$ theme configuration
</pre>
</div><div class='figure'>
<img alt='Output of the Theme Command Line Console' src='../images/theme%20console2.png' />
</div>
<p>The listing of available options and arguments to the <em>theme</em> commmand is slightly different from the <em>shopify</em> command. It does use the same API key and password to access shop resources. The configuration is saved as a file config.yml. The first step useful step once configured is to download the complete theme. $ theme download</p>
<p>Once the assets are downloaded setup the files under version control. Make a local repository with git and store the client’s code under version control for safety. Advanced developers might even add a git remote pointing at github so that all work is safely stored in a private repository there too.</p>
<div class='highlight'><pre>$ git init
$ git add .
$ git commit -m 'initial commit of Shopify code for client XYZ'
</pre>
</div>
<p>With the code in git it is a great time to start working on the theme. Use the <em>theme watch</em> command to <em>watch</em> the directory for any changes. As soon as a change is registered to a file, the theme watcher will transmit the changed file to the client site where the file was downloaded from. Any changes can be stored in git, ensuring a smooth and hassle free development experience.</p>
<div class='highlight'><pre>$ git commit -am 'Fixed that pesky jQuery error the client had from blindly copy and pasting some bad code off the Internet'
</pre>
</div>
<p>This is a very productive and safe workflow. The code is under version control and it is easy to edit theme code using your favorite tools. If in the future the client wants more work done you just use the <em>theme download</em> command to grab new files or changes to files initiated by the merchant or others. Git will keep track of all changes. You have a fighting chance when you are not the only person touching or editing a merchant site. Squashing some other designers work or other persons files is rarely an acceptable practice!</p>
</div>
</body>
</html>