I went trough the the shopifyApi documentation and it's explaining how to communicate with the API via post/put/get http verbs.
I am coding in Ruby and I was wondering where I could find a list of all the methods available (like product.add_metafield(params)).
I checked the gem server and didn't find any RDOC available for the api.
Thank you
Here is a neat trick. At your command-line try gem which shopify_api. That will list out the current version you are using for your current Ruby. Of course with RVM or RBEnv these vary wildly.
Copy and paste the result to your clipboard. An example from my CLI is:
/Users/fuzzy/.rvm/gems/ruby-1.9.3-p194/gems/shopify_api-3.0.1/lib/shopify_api.rb
You only need this part...
/Users/fuzzy/.rvm/gems/ruby-1.9.3-p194/gems/shopify_api-3.0.1/lib
With that in your clipboard, type subl or mate or vim or whatever your text editor is and paste in that path. You'll then have the gem at your disposal. If you navigate to the shopify_api/resources folder you'll see the product.rb file, showing off some methods you can use. You can see how most resources work this way. Learning Active Resource can also go a long way to showing off how the API gem provides functionality.
You can hack the gem once you get past this stage of exploration. You can re-open the modules and classes and add your own methods. Pretty neat stuff.
The command line interface based on Thor is also in there, and worth a good look. That is one of the coolest aspects of the gem in my opinion. see shopify_api/cli.rb
Related
I am running rails3 in Ubuntu and using gedit for coding. I am using RVM. To look at the gem source code I tried: bundle open jquery-rails
That doesn't work since I hadn't setup an editor. After setting gedit as the editor it still doesn't work because gedit can't be passed directories. I guess it only works with files. Too bad :(.
nathan.f77's answer to this question ( Lookup Gem or Plugin code packaged in a Rails3 application ) seems promising, but I wasn't able to follow his instructions. They lacked sufficient detail for me.
What is a very easy way to browse the source files for gems that I am using in my rails3 app?
bundle show jquery-rails should tell you where the gem source lives on your filesystem. Then open the file that you want.
CubaLibre's response got me half-way there. The other piece of the puzzle I was able to get from Ask Ubuntu.
Here are the steps to browse gem code in gedit using Ubuntu.
a. From the command line run:
gnome-open $(bundle show [gem-name])
b. This will open up the gem directory in nautilus. From there just double click on file you'd like to see and it will open up in gedit.
Assuming you have a default editor set in your terminal, on MacOS you can do something like this example (atom is my editor, but should work with sublime or textmate, vim, etc.):
atom $(bundle show name_of_gem)
I installed Ruby on Rails 3 using bash on OSX Lion.
When I wanted to use zsh and do a "rails -v" command I had "Rails is not currently installed on this system".
I just do not understand why. To me it's like "you can access all the files you want with bash not with zsh".
If I want to switch to zsh, will I have to install one more time Rails? delete the old one?
Is it secure and clever to use two shells when developing Rails applications?
What are your best practices?
Thanks in advance.
PS: I am new to programming and my installation is working fine. I even created one app.
EDIT: If you encounter the same problem I would encourage you to read the second answer first to get the rationale then the first one. Thanks to both of them.
While you are running bash, type at the command line echo $PATH.
Now start up your zsh command line, and type echo $PATH.
I bet the Rails path is not included in your zsh, right?
Look in your $HOME dir for .bash* files. See which one has the Rails PATH added.
Find your zsh .* env files and copy/paste the line you found above into the approriate file.
When I say .bash* and .* files, I mean hidden files in your home dir that you'll only find by doing ls -la. If you find a .profile file, that would be a good place to insert this.
I hope this helps.
P.S. as you appear to be a new user, if you get an answer that helps you please remember to mark it as accepted, and/or give it a + (or -) as a useful answer.
I just do not understand why. To me it's like "you can access all the
files you want with bash not with zsh".
As shellter said, you must have directories added to your path in order to run commands from the command line. For more information on PATHs take a look at the Intro to Linux guide. I know you are not using Linux but that section (and lots of others) is very much applicable.
If I want to switch to zsh, will I have to install one more time
Rails? delete the old one?
No, see note on paths above and take a look at the guide.
Is it secure and clever to use two shells when developing Rails
applications? What are your best practices?
It's not really something special to use two shells at once. It depends what you do in each. I often have 6 and 7 shells open, not all for the same thing. That is really up to you and how you work. The number of shells you use is more of a workflow thing than a "best-practices" issue.
I normally have 3 shells open when I do RoR work. One running autotest in the background, one running rails -server, and one where I actually edit files and run emacs. But again, this is not best practice as it is workflow. Do whatever makes you effective.
The only trouble you could get into occasionally running two shells is say, for example, you open a file in one and delete it in another. However, when you do this it is typically very obvious.
PS: I am new to programming and my installation is working fine. I
even created one app.
For Rails, I found this tutorial very helpful.
Also, you said you were new to programming. I don't know if this is the case, but I would suggest starting with basic Ruby, before jumping into Perl. Although the tutorial I linked above covers Rails-flavored Ruby.
I just created my first trac project, but I don't want the sample data, how can I disable that.
I read the documentation and there is the wiki remove command. do I have to use this for all pages? Are there easy way to disable the sample wiki?
Modification of the behavior of
trac-admin <path_to_env> initenv seems not even worth the hassle, because you only need to type
trac-admin <path_to_env> wiki remove '*'
into a system terminal to get rid of all default Trac wiki pages. You'll see a list of all deleted page names for confirmation. But you always make a db copy before messing with the db anyway, don't you?
Sorry but there is no easy way to diable the sample wiki in trac. I'm pretty sure this can be done with a custom script, though.
Trac stores the default pages imported into the wiki of a new environment as plaintext files in the file system.
For example, on my Gentoo box they can be found in /usr/lib64/python2.7/site-packages/trac/wiki/default-pages/.
You can move these out of the way (or just keep those you want) before calling trac-admin projectname initenv and it will only create the pages that are in the ´default-pages` directory at the time of the call.
A lot has been written about engine development, and using a dummy app for testing.
In our case we're developing an engine that is not a stand-alone entity, but has dependencies on a real Rails 3 application. We still want this code to live in an engine, and not become part of the app, because the engine's job is to import data from a legacy system that has its own tables and model mappings, and we want to eventually remove it again.
The data mappings between the old legacy tables and the new schema are complex, and we want to TDD (using rspec) the engine.
I've followed Jose Valim's book "Crafting Rails Appliations" and am using the enginex gem.
I've replaced /spec/dummy_app with a git submodule pointing to a real Rails 3 app.
I'm having trouble loading the models from the engine (undefined symbol errors), as the real app's Gemfile doesn't point to the engine, and I also can't modify config/application.rb, to require the engine (which is what the dummy app does, as explained on pages 15-16 of the book).
I'm including the engine's lib folder into the load path $: in spec_helper and the paths are available.
Putting the require into spec_helper.rb didn't solve the problem.
I'm wondering if there is an internal Rails API (or a clever monkey patch) to hook into the boot sequence of the real app and require the engine, without having to modify the real app's code (as it's in a submodule).
Another issue I'm not fully sure about is that I have 2 Gemfiles (one in the engine and one in the app), and when the engine is active, they should both be used.
Thoughts?
So, I figured out a few things and will answer my own question, now that I got it to work.
For simplicity, I'm going to refer to the name of my gem as "my_gem" and "MyGem":
In the engine.rb file, I added:
require 'my_gem'
require 'rails'
This fixed errors of the type:
my_gem/lib/my_gem/engine.rb:2: uninitialized constant MyGem::Rails (NameError)
In spec_helper.rb, I added right up top:
require 'bundler/setup'
require 'my_gem'
This is to make sure Bundler is initialized right away, and not through the app. That way I can load MyGem here, and it'll be hooked into the initialization sequence of the app. This fixes NameError exceptions for the engine's model classes.
That leaves the question of what Gemfile to use. The trouble is that my app has its own gemfile and the gem/engine needs its separate dependencies in its own Gemfile.
I couldn't find any API for Bundler to pass two Gemfile to it, in fact Bundler seems to be built around the assumption of a single authoritative Gemfile. So I generate one in spec_helper. I take the app's gemfile and append gemspec which points to the gem's dependency in GemSpec format. (The hint about gemspec is missing from Jose Valim's book by the way).
I don't know if there's a better way than concatenating files during test startup. If you know of one, please respond.
Helpful resources were:
Clarifying the Roles of the .gemspec and Gemfile by Yehuda Katz
Bundler Documentation for gemspec
I am working on a small toy project who is getting more and more releases. Until now, the documentation was just a set of pages in the wordpress blog I setup for the project. However, as time passes, new releases are out and I should update the online documentation to match the most recent release.
Unfortunately, if I do so, the docs for the previous releases will "disappear" as my doc pages are updated to the most recent version, therefore I decided to include the documentation in the release package and to keep the most recent documentation available online as a web page as well.
A trivial idea would be to wget the current docs from the wordpress pages, save them into the svn and therefore into the release package, repeating the procedure at every new release. Unfortunately, the HTML I get must be hacked by hand to fix the links (or I should hack wordpress to use BASE so that the HTML code is easily relocatable, something I don't want to do).
How should I handle the requirements of having at the same time:
user-browsable documentation for the proper version included in the downloadable package
most recent documentation available online (and properly styled with my web theme)
keep synchronized between the svn and the actual online contents (in wordpress, or something else that fits nicely with my wordpress setup)
easy to use
Thanks
Edit: started a bounty to see if I can lure more answers. I think this is a quite important issue, and it would be nice to have multiple hints and opinions for future readers.
I would check your pages into SVN, and then have your webserver update from its local SVN working copy when you're ready to release. Put everything into SVN--wordpress, CSS, HTML, etc.
WGet can convert all the links in the document for you. See the convert-links option:
http://www.gnu.org/software/wget/manual/html_node/Advanced-Usage.html
Using this in conjuction with the other methods could yield a solution.
I think there are two problems to be solved here
how and where to keep the documentation aligned with the code
where to publish the documentation
For 1 i think it's best to:
keep the documentation in a repository (SVN or git or whatever you already use for the code) as a set of files, instead of in a db as it is easier to keep a history of changes (an possibly to stay in par with the code releases
use an approach where the documentation is generated from a set of source files (you'd keep the sources in the repository) from which the html files for the distribution package or for publishing on the web are generated. The two could possibly differ, as on the web you'd need to keep some version information (in the URL) that you don't need when packaging a single release.
To do "2" there are several tools that may generate a static site. One of them is Jekyll it's in ruby and looks quite complete and customizable.
Assuming that you use a tool like jekyll and keep the files and source in SVN you might setup your repo in this way:
repo/
tags/
rel1.0/
source/
documentation/
rel2.0/
source/
documentation/
rel3.0/
source/
documentation/
trunk/
source/
documentation/
That is:
You keep the current documentation beside the source in the trunk
When you do a release you create a tag for the release
you configure your documentation generator to generate documentation for each of the repo/tags//documentation directory such that the documentation for each release is put in documentation_site/ directory
So to publish the documentation (point 2 above):
you copy on the server the contents of the documentation_site directory, putting it in the same base dir of your wordpress install or linking from that, such that each release doc can be accessed as: http://yoursite/project/docs/relXX/
you create a link to the current release documentation such that it can always be reached as http://yoursite/project/docs/current
The trick here is to publish the documentation always under a proper release identifier (in the URL, on the filesystem) and use a link (or a redirect) to make sure that the "current documentation" on the web server points to the current release.
I have seen some programs use help & manual. But I am a Mac user and I have no experience with it to know if it's any good. I'm looking for a solution myself for Mac.
For my own projects, if that were a need, I would create a sub-dir for the documentation, and have all the files refer from the known-base of there relatively. For example,
index.html -- refers to images/example.jpg
README
-- subdirs....
images/example.jpg
section/index.html -- links back to '../index.html',
-- refers to ../images/example.jpg
If the docs are included in the SVN/tarball download, then they are readable as-is. If they are generated from some original files, they would be pre-generated for a downloadable version.
Archive versions of the documentation can be unpacked/generated and placed into named directorys (eg docs/v1.05/)
Its a simple PHP script that can be written to get a list the subdirs of the /docs/ directory from the local disk and display a list, and highlighting the most recent, for example.